You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That overload is intended as it is used by the source cache to ensure empty changeset when no subscribers are registered. That said it may be worth having an overload to explicitly suppress the notification when using this constructor
Maybe I shall explain how I got to this:
EFCore uses the ObservableHashSet and I wanted to use this with DynamicData. My first try was to use the ObservableCollectionEx.ToObservableChangeSet<TCollection,T>(...) overload, which wasn't very successful as that HashSet's change notifications don't really work for a list with order.
So I basically rewrote it to match a Set, maybe this is of use for the library, feel free to add it in:
publicstaticIObservable<IChangeSet<TObject,TKey>>ToObservableChangeSet<TCollection,TObject,TKey>(thisTCollectionsource,Func<TObject,TKey>key)whereTCollection:INotifyCollectionChanged,ISet<TObject>{if(sourceisnull){thrownewArgumentNullException(nameof(source));}returnObservable.Create<IChangeSet<TObject,TKey>>(
observer =>{vardata=newChangeAwareCache<TObject,TKey>();foreach(variteminsource)data.Add(item,key(item));// <----- this right here is necessary, because the ChangeAwareCache ctor doesn't produce an initial ChangeSetif(data.Count>0){observer.OnNext(data.CaptureChanges());}returnsource.ObserveCollectionChanges().Scan(data,(cache,args)=>{varchanges=args.EventArgs;if(changes.NewItemsis not null){foreach(variteminchanges.NewItems.Cast<TObject>()){cache.Add(item,key(item));}}if(changes.OldItemsis not null){cache.Remove(changes.OldItems.Cast<TObject>().Select(key));}returncache;}).Select(cache =>cache.CaptureChanges()).SubscribeSafe(observer);});}
Describe the bug 🐞
looking through the code because of something unrelated the following took me by surprise:
https://github.com/reactivemarbles/DynamicData/blob/main/src/DynamicData/Cache/ChangeAwareCache.cs#L54
initializing the
ChangeAwareCache
with aDictionary
and subsequently callingCaptureChanges()
did not produce an initial ChangeSet!I don't know if that might have an effect on the whole library as for example the ChangeAwareList does have code for the initial ChangeSet
Step to reproduce
just code review
Reproduction repository
https://github.com/reactivemarbles/DynamicData
Expected behavior
to send an initial ChangeSet
Screenshots 🖼️
No response
IDE
No response
Operating system
No response
Version
No response
Device
No response
DynamicData Version
No response
Additional information ℹ️
No response
The text was updated successfully, but these errors were encountered: