public AsyncEvent <K> Observe <K>(Expression <Func <T, K> > property) { var prop = property.GetProperty(); if (_events.ContainsKey(prop)) { return(_events[prop] as AsyncEvent <K>); } var val = (K)_state[prop]; var ae = new AsyncEvent <K>(val); _events.Add(prop, ae); return(ae); }
public AsyncEvent <CollectionChanges <K> > Observe <K>(Expression <Func <T, IStateList <K> > > property) { var prop = property.GetProperty(); if (_events.ContainsKey(prop)) { return(_events[prop] as AsyncEvent <CollectionChanges <K> >); } var val = (List <K>)_state[prop]; var ae = new AsyncEvent <CollectionChanges <K> >(Changes.Init(val)) .OnSubscribe(async cb => await cb.Invoke(Changes.Init((List <K>)_state[prop]))); _events.Add(prop, ae); return(ae); }
/// <summary> /// Converts an AsyncEvent to IObservable of Unit (since there is not IObservable of void. Using the /// owner to control the weak action lifespan and unsubscribe when observer is disposed /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TOwner"></typeparam> /// <param name="source"></param> /// <param name="owner"></param> /// <returns></returns> public static IObservable <Unit> ToObservable <TOwner>(this AsyncEvent source, TOwner owner) where TOwner : INotifyDisposable { return(Observable.Create <Unit>(async observer => { Func <Task> handler = () => { observer.OnNext(Unit.Default); return Task.CompletedTask; }; await source.Subscribe(owner, handler); return Disposables.Call(() => { source.Unsubscribe(owner, handler); }); })); }
public ServiceCollectionField(IEnumerable <T> values = null) { if (values != null) { _items = new List <T>(values); } else { _items = new List <T>(); } Changed = new AsyncEvent <CollectionChanges <T> >(Changes.Init(_items)) // instead of returning the latest change, on subscribe, we return a reset to the entire list .OnSubscribe(async cb => { await cb.Invoke(Changes.Init(_items)); }); }
public ServiceField(T value) { _value = value; Changed = new AsyncEvent <T>(_value); }