Ejemplo n.º 1
0
 public static IObservable <IEnumerable <TValue> > CachePerElement <TDescriptor, TValue>(
     this IObservable <IEnumerable <TDescriptor> > items,
     Func <TDescriptor, TValue> getValue,
     Action <TValue> valueRemoved = null)
 {
     return(items.CachePerElement(d => d, getValue, valueRemoved));
 }
Ejemplo n.º 2
0
        IObservable <TOut> WatchSet <T, TOut>(IObservable <IEnumerable <T> > sets, Func <T, IObservable <TOut> > onItemAdded)
        {
            return(sets
                   .CachePerElement(
                       data => data,
                       (data) =>
            {
                var disposable = new BehaviorSubject <Optional <IDisposable> >(Optional.None());
                var proxy = new Subject <TOut>();
                var changes = Observable.Create <TOut>(
                    observer =>
                {
                    var dis = proxy.Subscribe(observer);

                    if (!disposable.Value.HasValue)
                    {
                        disposable.OnNext(Optional.Some(onItemAdded(data).Subscribe(proxy)));
                    }

                    return dis;
                });

                return new
                {
                    changes,
                    dispose = disposable
                };
            }, v => v.dispose.Value.Do(d => d.Dispose()))
                   .Select(p => p.Select(v => v.changes).Merge())
                   .Switch());
        }