Beispiel #1
0
        private static IDisposable ItemPropertyChangedCore <TCollection, TItem, TProperty, T>(
            this IObservable <TCollection> source,
            IObserver <T> observer,
            Expression <Func <TItem, TProperty> > property,
            Func <TItem, object, PropertyChangedEventArgs, SourceAndValue <INotifyPropertyChanged, TProperty>, T> create)
            where TCollection : class, IEnumerable <TItem>, INotifyCollectionChanged
            where TItem : class, INotifyPropertyChanged
        {
            var tracker = ItemsTracker.Create((TCollection)null, NotifyingPath.GetOrCreate(property));

            tracker.TrackedItemChanged += Handler;
            var subscription = source.Subscribe(x => tracker.UpdateSource(x));

            return(new CompositeDisposable(3)
            {
                Disposable.Create(() => tracker.TrackedItemChanged -= Handler),
                tracker,
                subscription,
            });

            void Handler(TItem item, object sender, PropertyChangedEventArgs args, SourceAndValue <INotifyPropertyChanged, TProperty> sourceAndValue)
            {
                observer.OnNext(create(item, sender, args, sourceAndValue));
            }
        }
Beispiel #2
0
        private static IDisposable ObserveItemPropertyChangedCore <TCollection, TItem, TProperty, T>(
            this TCollection source,
            IObserver <T> o,
            Expression <Func <TItem, TProperty> > property,
            bool signalInitial,
            Func <TItem, object, PropertyChangedEventArgs, SourceAndValue <INotifyPropertyChanged, TProperty>, T> create)
            where TCollection : class, IEnumerable <TItem>, INotifyCollectionChanged
            where TItem : class, INotifyPropertyChanged
        {
            var tracker = ItemsTracker.Create(
                signalInitial
                    ? null
                    : source,
                NotifyingPath.GetOrCreate(property));

            TrackedItemPropertyChangedEventHandler <TItem, TProperty> handler =
                (item, sender, args, sourceAndValue) => o.OnNext(
                    create(
                        item,
                        sender,
                        args,
                        sourceAndValue));

            tracker.TrackedItemChanged += handler;
            if (signalInitial)
            {
                tracker.UpdateSource(source);
            }

            return(new CompositeDisposable(2)
            {
                Disposable.Create(() => tracker.TrackedItemChanged -= handler),
                tracker
            });
        }