/// <summary> /// Returns a observable of cache changes preceeded with the initital cache state /// </summary> /// <param name="predicate">The result will be filtered using the specfied predicate.</param> /// <returns></returns> public IObservable <IChangeSet <TObject, TKey> > Connect(Func <TObject, bool> predicate = null) { return(Observable.Create <IChangeSet <TObject, TKey> > ( observer => { if (predicate == null) { return Observable.Return(_innerCache.GetInitialUpdates()) .Concat(_changes) .SubscribeSafe(observer); } var updater = new FilteredUpdater <TObject, TKey>(new ChangeAwareCache <TObject, TKey>(), predicate); var filtered = updater.Update(_innerCache.GetInitialUpdates(predicate)); if (filtered.Count != 0) { observer.OnNext(filtered); } return _changes .Select(updater.Update) .NotEmpty() .SubscribeSafe(observer); })); }
/// <summary> /// Returns a observable of cache changes preceded with the initial cache state /// </summary> /// <param name="predicate">The result will be filtered using the specified predicate.</param> /// <returns></returns> public IObservable <IChangeSet <TObject, TKey> > Connect(Func <TObject, bool> predicate = null) { return(Observable.Defer(() => { var initial = _innerCache.GetInitialUpdates(predicate); var changes = Observable.Return(initial).Concat(_changes); return (predicate == null ? changes : changes.Filter(predicate)) .NotEmpty(); })); }