public ServiceCollectionAdapter <T, TVM> From(IStateCollectionReader <T> source) { Source = source; return(this); }
public ItemsService() { TodoItems = _store.CreateReader(this, m => m.TodoItems); }
/// <summary> /// Subscribes to a StateCollectionReader and exposes it as collection of (immuable) list values /// </summary> public static IObservable <ImmutableList <T> > ObserveValues <T, TOwner>(this IStateCollectionReader <T> source, TOwner owner) where TOwner : INotifyDisposable { return(source.ObserveChanges(owner).Select(changeSet => changeSet.NewValues.ToImmutableList())); }
/// <summary> /// Subscribes to a StateCollectionReader and exposes it as an observable of DiffResult. Note that each IChange /// is converted into a single DiffResult, so one StateCollectionReader Change event may yield many DiffResult instances. /// You can use the result of this method to apply changes onto an observable collection /// </summary> public static IObservable <DiffResults <T> > ObserveDiffs <T, TOwner>(this IStateCollectionReader <T> source, TOwner owner) where TOwner : INotifyDisposable { return(source.ObserveChanges(owner).ToDiffResult()); }
/// <summary> /// Subscribes to an IStateCollectionReader and exposes it as Observable of CollectionChanges /// </summary> public static IObservable <CollectionChanges <T> > ObserveChanges <T, TOwner>(this IStateCollectionReader <T> source, TOwner owner) where TOwner : INotifyDisposable { return(Observable.Create <CollectionChanges <T> >(async observer => { Func <CollectionChanges <T>, Task> handler = val => { observer.OnNext(val); return Task.CompletedTask; }; await source.Changed.Subscribe(owner, handler); return Disposables.Call(() => { source.Changed.Unsubscribe(owner, handler); }); })); }