Skip to content

Commit f9f02c8

Browse files
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
1 parent ce71991 commit f9f02c8

7 files changed

Lines changed: 20 additions & 74 deletions

File tree

src/DynamicData.Tests/Binding/ObservableCollectionBindCacheFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void RunTest(bool useReplace)
8585
var collection = new ObservableCollectionExtended<Person>();
8686

8787
using var source = new SourceCache<Person, string>(p => p.Name);
88-
using var binder = source.Connect().Bind(collection, useReplaceForUpdates: useReplace).Subscribe();
88+
using var binder = source.Connect().Bind(collection, new ObservableCollectionAdaptor<Person, string>(useReplaceForUpdates: useReplace)).Subscribe();
8989

9090

9191
NotifyCollectionChangedAction action = default;

src/DynamicData/Cache/Internal/AnonymousQuery.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ internal sealed class AnonymousQuery<TObject, TKey> : IQuery<TObject, TKey>
1313
{
1414
private readonly Cache<TObject, TKey> _cache;
1515

16-
public AnonymousQuery(Cache<TObject, TKey> cache)
17-
{
18-
_cache = cache.Clone();
19-
}
16+
public AnonymousQuery(Cache<TObject, TKey> cache) => _cache = cache.Clone();
2017

2118
public int Count => _cache.Count;
2219

@@ -26,8 +23,5 @@ public AnonymousQuery(Cache<TObject, TKey> cache)
2623

2724
public IEnumerable<KeyValuePair<TKey, TObject>> KeyValues => _cache.KeyValues;
2825

29-
public Optional<TObject> Lookup(TKey key)
30-
{
31-
return _cache.Lookup(key);
32-
}
26+
public Optional<TObject> Lookup(TKey key) => _cache.Lookup(key);
3327
}

src/DynamicData/Cache/Internal/Cache.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ public Cache(int capacity = -1)
2323
_data = capacity > 1 ? new Dictionary<TKey, TObject>(capacity) : new Dictionary<TKey, TObject>();
2424
}
2525

26-
public Cache(Dictionary<TKey, TObject> data)
27-
{
28-
_data = data;
29-
}
26+
public Cache(Dictionary<TKey, TObject> data) => _data = data;
3027

3128
public int Count => _data.Count;
3229

@@ -36,20 +33,11 @@ public Cache(Dictionary<TKey, TObject> data)
3633

3734
public IEnumerable<KeyValuePair<TKey, TObject>> KeyValues => _data;
3835

39-
public void AddOrUpdate(TObject item, TKey key)
40-
{
41-
_data[key] = item;
42-
}
36+
public void AddOrUpdate(TObject item, TKey key) => _data[key] = item;
4337

44-
public void Clear()
45-
{
46-
_data.Clear();
47-
}
38+
public void Clear() => _data.Clear();
4839

49-
public Cache<TObject, TKey> Clone()
50-
{
51-
return new(new Dictionary<TKey, TObject>(_data));
52-
}
40+
public Cache<TObject, TKey> Clone() => new(new Dictionary<TKey, TObject>(_data));
5341

5442
public void Clone(IChangeSet<TObject, TKey> changes)
5543
{

src/DynamicData/Cache/Internal/EditDiff.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
// Roland Pheasant licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

5-
using System;
6-
using System.Collections.Generic;
7-
using System.Linq;
8-
95
using DynamicData.Kernel;
106

117
namespace DynamicData.Cache.Internal;

src/DynamicData/Cache/Internal/FilterEx.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,9 @@ public static void FilterChanges<TObject, TKey>(this ChangeAwareCache<TObject, T
6060
cache.Refresh(key);
6161
}
6262
}
63-
else
63+
else if (existing.HasValue)
6464
{
65-
if (existing.HasValue)
66-
{
67-
cache.Remove(key);
68-
}
65+
cache.Remove(key);
6966
}
7067
}
7168

src/DynamicData/Cache/ObservableCacheEx.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,9 @@ public static IObservable<IChangeSet<TObject, TKey>> BatchIf<TObject, TKey>(this
585585
/// <param name="source">The source.</param>
586586
/// <param name="destination">The destination.</param>
587587
/// <param name="refreshThreshold">The number of changes before a reset notification is triggered.</param>
588-
/// <param name="useReplaceForUpdates"> Use replace instead of remove / add for updates. NB: Some platforms to not support replace notifications for binding.</param>
589588
/// <returns>An observable which will emit change sets.</returns>
590589
/// <exception cref="System.ArgumentNullException">source.</exception>
591-
public static IObservable<IChangeSet<TObject, TKey>> Bind<TObject, TKey>(this IObservable<IChangeSet<TObject, TKey>> source, IObservableCollection<TObject> destination, int refreshThreshold = 25, bool useReplaceForUpdates = false)
590+
public static IObservable<IChangeSet<TObject, TKey>> Bind<TObject, TKey>(this IObservable<IChangeSet<TObject, TKey>> source, IObservableCollection<TObject> destination, int refreshThreshold = 25)
592591
where TKey : notnull
593592
{
594593
if (source is null)
@@ -601,8 +600,7 @@ public static IObservable<IChangeSet<TObject, TKey>> Bind<TObject, TKey>(this IO
601600
throw new ArgumentNullException(nameof(destination));
602601
}
603602

604-
var updater = new ObservableCollectionAdaptor<TObject, TKey>(refreshThreshold, useReplaceForUpdates);
605-
return source.Bind(destination, updater);
603+
return source.Bind(destination, new ObservableCollectionAdaptor<TObject, TKey>(refreshThreshold));
606604
}
607605

608606
/// <summary>

src/DynamicData/Kernel/Optional.cs

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -78,60 +78,39 @@ public T Value
7878
/// </summary>
7979
/// <param name="value">The value.</param>
8080
/// <returns>The optional value.</returns>
81-
public static implicit operator Optional<T>(T? value)
82-
{
83-
return ToOptional(value);
84-
}
81+
public static implicit operator Optional<T>(T? value) => ToOptional(value);
8582

8683
/// <summary>
8784
/// Explicit cast from option to value.
8885
/// </summary>
8986
/// <param name="value">The value.</param>
9087
/// <returns>The optional value.</returns>
91-
public static explicit operator T?(Optional<T> value)
92-
{
93-
return FromOptional(value);
94-
}
88+
public static explicit operator T?(Optional<T> value) => FromOptional(value);
9589

96-
public static bool operator ==(Optional<T> left, Optional<T> right)
97-
{
98-
return left.Equals(right);
99-
}
90+
public static bool operator ==(Optional<T> left, Optional<T> right) => left.Equals(right);
10091

101-
public static bool operator !=(Optional<T> left, Optional<T> right)
102-
{
103-
return !left.Equals(right);
104-
}
92+
public static bool operator !=(Optional<T> left, Optional<T> right) => !left.Equals(right);
10593

10694
/// <summary>
10795
/// Creates the specified value.
10896
/// </summary>
10997
/// <param name="value">The value.</param>
11098
/// <returns>The optional value.</returns>
111-
public static Optional<T> Create(T? value)
112-
{
113-
return new(value);
114-
}
99+
public static Optional<T> Create(T? value) => new(value);
115100

116101
/// <summary>
117102
/// Gets the value from the optional value.
118103
/// </summary>
119104
/// <param name="value">The optional value.</param>
120105
/// <returns>The value.</returns>
121-
public static T? FromOptional(Optional<T> value)
122-
{
123-
return value.Value;
124-
}
106+
public static T? FromOptional(Optional<T> value) => value.Value;
125107

126108
/// <summary>
127109
/// Gets the optional from a value.
128110
/// </summary>
129111
/// <param name="value">The value to get the optional for.</param>
130112
/// <returns>The optional.</returns>
131-
public static Optional<T> ToOptional(T? value)
132-
{
133-
return new(value);
134-
}
113+
public static Optional<T> ToOptional(T? value) => new(value);
135114

136115
/// <inheritdoc />
137116
public bool Equals(Optional<T> other)
@@ -206,19 +185,13 @@ public static class Optional
206185
/// </summary>
207186
/// <typeparam name="T">The type of the item.</typeparam>
208187
/// <returns>The optional value.</returns>
209-
public static Optional<T> None<T>()
210-
{
211-
return Optional<T>.None;
212-
}
188+
public static Optional<T> None<T>() => Optional<T>.None;
213189

214190
/// <summary>
215191
/// Wraps the specified value in an Optional container.
216192
/// </summary>
217193
/// <typeparam name="T">The type of the item.</typeparam>
218194
/// <param name="value">The value.</param>
219195
/// <returns>The optional value.</returns>
220-
public static Optional<T> Some<T>(T value)
221-
{
222-
return new(value);
223-
}
196+
public static Optional<T> Some<T>(T value) => new(value);
224197
}

0 commit comments

Comments
 (0)