private ReadOnlyFilteredView(IEnumerable <T> source, Func <T, bool> filter, IScheduler scheduler, TimeSpan bufferTime, IReadOnlyList <IObservable <object> > triggers) { Ensure.NotNull(source, nameof(source)); Ensure.NotNull(filter, nameof(filter)); this.source = source; this.Filter = filter; this.BufferTime = bufferTime; this.SetSource(this.Filtered()); this.refreshSubscription = FilteredRefresher.Create(this, source, bufferTime, triggers, scheduler, false) .Subscribe(this.Refresh); }
/// <summary> /// /// </summary> /// <param name="source">The collection to wrap</param> /// <param name="filter"></param> /// <param name="bufferTime">The time to defer updates, useful if many triggers fire in short time. Then it will be only one Reset</param> /// <param name="scheduler">The scheduler used when throttling. The collection changed events are raised on this scheduler</param> /// <param name="triggers">Triggers when to re evaluate the filter</param> public FilteredView( IList <T> source, Func <T, bool> filter, TimeSpan bufferTime, IScheduler scheduler, params IObservable <object>[] triggers) : base(source, Filtered(source, filter)) { if (filter == null) { filter = x => true; } this.scheduler = scheduler; this.bufferTime = bufferTime; this.filter = filter; if (triggers == null || triggers.Length == 0) { this.triggers = new ObservableCollection <IObservable <object> >(); } else { this.triggers = new ObservableCollection <IObservable <object> >(triggers); } this.refreshSubscription.Disposable = FilteredRefresher.Create(this, source, bufferTime, triggers, scheduler, false) .ObserveOn(scheduler ?? Scheduler.Immediate) .Subscribe(this.Refresh); var observables = new IObservable <object>[] { this.Triggers.ObserveCollectionChanged(false), this.ObservePropertyChangedSlim(nameof(this.Filter), false), this.ObservePropertyChangedSlim(nameof(this.BufferTime), false) }; observables.Merge() .ThrottleOrDefault(bufferTime, scheduler) .Subscribe(_ => this.refreshSubscription.Disposable = FilteredRefresher.Create(this, source, bufferTime, triggers, scheduler, true) .ObserveOn(scheduler ?? Scheduler.Immediate) .Subscribe(this.Refresh)); }