Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        /// <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);
                });
            }));
        }
Exemplo n.º 4
0
        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));
            });
        }
Exemplo n.º 5
0
 public ServiceField(T value)
 {
     _value  = value;
     Changed = new AsyncEvent <T>(_value);
 }