示例#1
0
        void setupRx(IEnumerable <T> initialContents = null, double resetChangeThreshold = 0.3, IScheduler scheduler = null)
        {
            scheduler = scheduler ?? RxApp.MainThreadScheduler;

            _inner = _inner ?? new List <T>();

            _changing = new Subject <NotifyCollectionChangedEventArgs>();
            _changing.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(raiseCollectionChanging);

            _changed = new Subject <NotifyCollectionChangedEventArgs>();
            _changed.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(raiseCollectionChanged);

            ResetChangeThreshold = resetChangeThreshold;

            _beforeItemsAdded   = new Lazy <Subject <T> >(() => new Subject <T>());
            _itemsAdded         = new Lazy <Subject <T> >(() => new Subject <T>());
            _beforeItemsRemoved = new Lazy <Subject <T> >(() => new Subject <T>());
            _itemsRemoved       = new Lazy <Subject <T> >(() => new Subject <T>());
            _itemChanging       = new Lazy <ISubject <IReactivePropertyChangedEventArgs <T> > >(() => new ScheduledSubject <IReactivePropertyChangedEventArgs <T> >(scheduler));
            _itemChanged        = new Lazy <ISubject <IReactivePropertyChangedEventArgs <T> > >(() => new ScheduledSubject <IReactivePropertyChangedEventArgs <T> >(scheduler));
            _beforeItemsMoved   = new Lazy <Subject <IMoveInfo <T> > >(() => new Subject <IMoveInfo <T> >());
            _itemsMoved         = new Lazy <Subject <IMoveInfo <T> > >(() => new Subject <IMoveInfo <T> >());

            // NB: We have to do this instead of initializing _inner so that
            // Collection<T>'s accounting is correct
            foreach (var item in initialContents ?? Enumerable.Empty <T>())
            {
                Add(item);
            }

            // NB: ObservableCollection has a Secret Handshake with WPF where
            // they fire an INPC notification with the token "Item[]". Emulate
            // it here
            CountChanging.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(_ => this.RaisePropertyChanging("Count"));

            CountChanged.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(_ => this.RaisePropertyChanged("Count"));

            IsEmptyChanged.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(_ => this.RaisePropertyChanged("IsEmpty"));

            Changing.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(_ => this.RaisePropertyChanging("Item[]"));

            Changed.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(_ => this.RaisePropertyChanged("Item[]"));
        }
示例#2
0
        void setupRx(IEnumerable <T> initialContents = null, double resetChangeThreshold = 0.3)
        {
            _inner = _inner ?? new List <T>();

            _changing = new Subject <NotifyCollectionChangedEventArgs>();
            _changing.Where(_ => _suppressionRefCount == 0).Subscribe(raiseCollectionChanging);

            _changed = new Subject <NotifyCollectionChangedEventArgs>();
            _changed.Where(_ => _suppressionRefCount == 0).Subscribe(raiseCollectionChanged);

            ResetChangeThreshold = resetChangeThreshold;

            _beforeItemsAdded   = new Lazy <Subject <T> >(() => new Subject <T>());
            _itemsAdded         = new Lazy <Subject <T> >(() => new Subject <T>());
            _beforeItemsRemoved = new Lazy <Subject <T> >(() => new Subject <T>());
            _itemsRemoved       = new Lazy <Subject <T> >(() => new Subject <T>());
            _itemChanging       = new Lazy <Subject <IObservedChange <T, object> > >(() => new Subject <IObservedChange <T, object> >());
            _itemChanged        = new Lazy <Subject <IObservedChange <T, object> > >(() => new Subject <IObservedChange <T, object> >());
            _beforeItemsMoved   = new Lazy <Subject <IMoveInfo <T> > >(() => new Subject <IMoveInfo <T> >());
            _itemsMoved         = new Lazy <Subject <IMoveInfo <T> > >(() => new Subject <IMoveInfo <T> >());

            // NB: We have to do this instead of initializing _inner so that
            // Collection<T>'s accounting is correct
            foreach (var item in initialContents ?? Enumerable.Empty <T>())
            {
                Add(item);
            }

            // NB: ObservableCollection has a Secret Handshake with WPF where
            // they fire an INPC notification with the token "Item[]". Emulate
            // it here
            CountChanging.Where(_ => _suppressionRefCount == 0).Select(x => new PropertyChangingEventArgs("Count")).Subscribe(this.raisePropertyChanging);

            CountChanged.Where(_ => _suppressionRefCount == 0).Select(x => new PropertyChangedEventArgs("Count")).Subscribe(this.raisePropertyChanged);

            IsEmptyChanged.Where(_ => _suppressionRefCount == 0).Select(x => new PropertyChangedEventArgs("IsEmpty")).Subscribe(this.raisePropertyChanged);

            Changing.Where(_ => _suppressionRefCount == 0).Select(x => new PropertyChangingEventArgs("Item[]")).Subscribe(this.raisePropertyChanging);

            Changed.Where(_ => _suppressionRefCount == 0).Select(x => new PropertyChangedEventArgs("Item[]")).Subscribe(this.raisePropertyChanged);
        }