Search code examples
c#reactiveuidynamic-data

Subscribe to any changes in a SourceCache?


There are two SourceCache as root sources: SourceCache1 and SourceCache2. I also have two ReadOnlyObservableCache derived from SourceCache1 and SourceCache2: DerivedReadOnlyObservableCache1 and DerivedReadOnlyObservableCache2.

I would like to refresh DerivedReadOnlyObservableCache2 when anything is changed in SourceCache1 (or DerivedReadOnlyObservableCache1).

Is it possible to get notified when anything is changed in a SourceCache or ReadOnlyObservableCaches? I want to be notified when either an item is added, removed or any property is changed of an item in the collection.


Solution

  • there is ForEachChange() that allows you to track the changes in an ObservableCache. For example: _sourceCache1.Connect().ForEachChange(x=>Debug.WriteLine($"{x.Reason}{x.Key}")).ObserveOn(RxApp.MainThreadScheduler).Bind(out _source1).Subscribe();