From f9f02c812f8460b5d830133de9d1c7496e03f4be Mon Sep 17 00:00:00 2001 From: Roland Pheasant Date: Tue, 18 Oct 2022 05:36:48 -0400 Subject: [PATCH] Housekeeping/revert sort (#650) * Code cleanup - no material changes * Revert useReplaceForUpdates for ObservableCacheEx.Bind, which is not in prod anyway. To use, construct own ObservableCollectionAdaptor --- .../ObservableCollectionBindCacheFixture.cs | 2 +- .../Cache/Internal/AnonymousQuery.cs | 10 +---- src/DynamicData/Cache/Internal/Cache.cs | 20 ++------- src/DynamicData/Cache/Internal/EditDiff.cs | 4 -- src/DynamicData/Cache/Internal/FilterEx.cs | 7 +-- src/DynamicData/Cache/ObservableCacheEx.cs | 6 +-- src/DynamicData/Kernel/Optional.cs | 45 ++++--------------- 7 files changed, 20 insertions(+), 74 deletions(-) diff --git a/src/DynamicData.Tests/Binding/ObservableCollectionBindCacheFixture.cs b/src/DynamicData.Tests/Binding/ObservableCollectionBindCacheFixture.cs index c17d59e64..70be9699d 100644 --- a/src/DynamicData.Tests/Binding/ObservableCollectionBindCacheFixture.cs +++ b/src/DynamicData.Tests/Binding/ObservableCollectionBindCacheFixture.cs @@ -85,7 +85,7 @@ void RunTest(bool useReplace) var collection = new ObservableCollectionExtended(); using var source = new SourceCache(p => p.Name); - using var binder = source.Connect().Bind(collection, useReplaceForUpdates: useReplace).Subscribe(); + using var binder = source.Connect().Bind(collection, new ObservableCollectionAdaptor(useReplaceForUpdates: useReplace)).Subscribe(); NotifyCollectionChangedAction action = default; diff --git a/src/DynamicData/Cache/Internal/AnonymousQuery.cs b/src/DynamicData/Cache/Internal/AnonymousQuery.cs index 68bca0593..5e77ae9da 100644 --- a/src/DynamicData/Cache/Internal/AnonymousQuery.cs +++ b/src/DynamicData/Cache/Internal/AnonymousQuery.cs @@ -13,10 +13,7 @@ internal sealed class AnonymousQuery : IQuery { private readonly Cache _cache; - public AnonymousQuery(Cache cache) - { - _cache = cache.Clone(); - } + public AnonymousQuery(Cache cache) => _cache = cache.Clone(); public int Count => _cache.Count; @@ -26,8 +23,5 @@ public AnonymousQuery(Cache cache) public IEnumerable> KeyValues => _cache.KeyValues; - public Optional Lookup(TKey key) - { - return _cache.Lookup(key); - } + public Optional Lookup(TKey key) => _cache.Lookup(key); } diff --git a/src/DynamicData/Cache/Internal/Cache.cs b/src/DynamicData/Cache/Internal/Cache.cs index 43ac910eb..5e6af39d7 100644 --- a/src/DynamicData/Cache/Internal/Cache.cs +++ b/src/DynamicData/Cache/Internal/Cache.cs @@ -23,10 +23,7 @@ public Cache(int capacity = -1) _data = capacity > 1 ? new Dictionary(capacity) : new Dictionary(); } - public Cache(Dictionary data) - { - _data = data; - } + public Cache(Dictionary data) => _data = data; public int Count => _data.Count; @@ -36,20 +33,11 @@ public Cache(Dictionary data) public IEnumerable> KeyValues => _data; - public void AddOrUpdate(TObject item, TKey key) - { - _data[key] = item; - } + public void AddOrUpdate(TObject item, TKey key) => _data[key] = item; - public void Clear() - { - _data.Clear(); - } + public void Clear() => _data.Clear(); - public Cache Clone() - { - return new(new Dictionary(_data)); - } + public Cache Clone() => new(new Dictionary(_data)); public void Clone(IChangeSet changes) { diff --git a/src/DynamicData/Cache/Internal/EditDiff.cs b/src/DynamicData/Cache/Internal/EditDiff.cs index 80efb34b9..de71536d5 100644 --- a/src/DynamicData/Cache/Internal/EditDiff.cs +++ b/src/DynamicData/Cache/Internal/EditDiff.cs @@ -2,10 +2,6 @@ // Roland Pheasant licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Linq; - using DynamicData.Kernel; namespace DynamicData.Cache.Internal; diff --git a/src/DynamicData/Cache/Internal/FilterEx.cs b/src/DynamicData/Cache/Internal/FilterEx.cs index f608850a2..9dba8644b 100644 --- a/src/DynamicData/Cache/Internal/FilterEx.cs +++ b/src/DynamicData/Cache/Internal/FilterEx.cs @@ -60,12 +60,9 @@ public static void FilterChanges(this ChangeAwareCache> BatchIf(this /// The source. /// The destination. /// The number of changes before a reset notification is triggered. - /// Use replace instead of remove / add for updates. NB: Some platforms to not support replace notifications for binding. /// An observable which will emit change sets. /// source. - public static IObservable> Bind(this IObservable> source, IObservableCollection destination, int refreshThreshold = 25, bool useReplaceForUpdates = false) + public static IObservable> Bind(this IObservable> source, IObservableCollection destination, int refreshThreshold = 25) where TKey : notnull { if (source is null) @@ -601,8 +600,7 @@ public static IObservable> Bind(this IO throw new ArgumentNullException(nameof(destination)); } - var updater = new ObservableCollectionAdaptor(refreshThreshold, useReplaceForUpdates); - return source.Bind(destination, updater); + return source.Bind(destination, new ObservableCollectionAdaptor(refreshThreshold)); } /// diff --git a/src/DynamicData/Kernel/Optional.cs b/src/DynamicData/Kernel/Optional.cs index cb8de3393..845160757 100644 --- a/src/DynamicData/Kernel/Optional.cs +++ b/src/DynamicData/Kernel/Optional.cs @@ -78,60 +78,39 @@ public T Value /// /// The value. /// The optional value. - public static implicit operator Optional(T? value) - { - return ToOptional(value); - } + public static implicit operator Optional(T? value) => ToOptional(value); /// /// Explicit cast from option to value. /// /// The value. /// The optional value. - public static explicit operator T?(Optional value) - { - return FromOptional(value); - } + public static explicit operator T?(Optional value) => FromOptional(value); - public static bool operator ==(Optional left, Optional right) - { - return left.Equals(right); - } + public static bool operator ==(Optional left, Optional right) => left.Equals(right); - public static bool operator !=(Optional left, Optional right) - { - return !left.Equals(right); - } + public static bool operator !=(Optional left, Optional right) => !left.Equals(right); /// /// Creates the specified value. /// /// The value. /// The optional value. - public static Optional Create(T? value) - { - return new(value); - } + public static Optional Create(T? value) => new(value); /// /// Gets the value from the optional value. /// /// The optional value. /// The value. - public static T? FromOptional(Optional value) - { - return value.Value; - } + public static T? FromOptional(Optional value) => value.Value; /// /// Gets the optional from a value. /// /// The value to get the optional for. /// The optional. - public static Optional ToOptional(T? value) - { - return new(value); - } + public static Optional ToOptional(T? value) => new(value); /// public bool Equals(Optional other) @@ -206,10 +185,7 @@ public static class Optional /// /// The type of the item. /// The optional value. - public static Optional None() - { - return Optional.None; - } + public static Optional None() => Optional.None; /// /// Wraps the specified value in an Optional container. @@ -217,8 +193,5 @@ public static Optional None() /// The type of the item. /// The value. /// The optional value. - public static Optional Some(T value) - { - return new(value); - } + public static Optional Some(T value) => new(value); }