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); }
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)); }); }