public static IObservable <IChangeSet <TObject, TKey> > AutoRefresh <TObject, TKey, TAny>(this IObservable <IChangeSet <TObject, TKey> > source, Func <TObject, IObservable <TAny> > reevaluator, TimeSpan?buffer = null, IScheduler scheduler = null) { return(source.AutoRefresh((t, v) => reevaluator(t), buffer, scheduler)); }
/// <summary> /// Automatically refresh downstream operators when properties change. /// </summary> /// <typeparam name="TObject"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="source">The source observable</param> /// <param name="properties">Properties to observe. Specify one or more properties to monitor, otherwise leave blank </param> /// <param name="buffer">Apply a buffer period to batch up changes when the properties of one or more items change</param> /// <param name="scheduler">The scheduler</param> /// <returns></returns> public static IObservable <IChangeSet <TObject, TKey> > AutoRefresh <TObject, TKey>(this IObservable <IChangeSet <TObject, TKey> > source, IEnumerable <string> properties = null, TimeSpan?buffer = null, IScheduler scheduler = null) where TObject : INotifyPropertyChanged { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.AutoRefresh((t, v) => t.WhenAnyPropertyChanged(properties?.ToArray() ?? new string[0]), buffer, scheduler)); }
public AutoRefreshForPropertyChanges(IObservable <IChangeSet <MutableThing, int> > dataSource) { /* * As per above example but in cases where the observable cache is not available * * NB: I created a new operator (See DynamicDataEx.cs in infrastructure folder which will be added to dynamic data in the next release) */ DistinctCount = dataSource .AutoRefresh(new[] { nameof(MutableThing.Value) }) .DistinctValues(m => m.Value) .Count(); }
public GameModel(Guid id, IObservable <IChangeSet <PlayModel, Guid> > plays, IObservable <IChangeSet <LinkedGameModel, Guid> > linkedGames) : base(id) { IsGenuine = true; Rating = 0; DesireToPlay = 10; plays.ObserveOn(RxApp.MainThreadScheduler) .Bind(out _plays) .Subscribe(); linkedGames .ObserveOn(RxApp.MainThreadScheduler) .Bind(out _linkedGames) .Subscribe(); plays.AutoRefresh(p => p.Duration) .ToCollection().Select(collection => collection.Select(p => p.Duration.Ticks).Sum()) .Select(TimeSpan.FromTicks) .ToPropertyEx(this, p => p.TotalTimePlayed); this.WhenAnyValue(p => p.TotalTimePlayed, p => p.PurchasePrice, p => p.SellPrice) .Select(p => TotalTimePlayed.TotalHours > 0 ? (PurchasePrice - SellPrice) / TotalTimePlayed.TotalHours : 0) .ToPropertyEx(this, x => x.Value); }
public IObservable <IChangeSet <TObject> > Run() { return(_source.AutoRefresh(_propertySelector, propertyChangeThrottle: _throttle, scheduler: _scheduler).Filter(_predicate)); }