Example #1
0
        public static IObservableResult <TResult> GetObservable <TCollection, TResult>(this TCollection collection, Func <TCollection, TResult> get, Action <TCollection, NotifyCollectionChangedEventArgs, Action> subscribeExtra = null)
            where TCollection : INotifyCollectionChanged
        {
            subscribeExtra = subscribeExtra ?? ((c, e, a) => {});
            var result = new ObservableValue <TResult>(get(collection));

            collection.CollectionChanged += (sender, e) => {
                result.Value = get(collection);
                subscribeExtra(collection, e, () => result.Value = get(collection));
            };

            return(result);
        }
Example #2
0
        public IObservableResult <TResult> GetObservable <TResult>(Func <T, TResult> get, Action <T, T, Action> subscribeExtra = null)
        {
            var result    = new ObservableValue <TResult>(get(Value));
            var lastValue = Value;

            PropertyChanged += (sender, _) => {
                var that = (ObservableValue <T>)sender;
                result.Value = get(that.Value);
                if (subscribeExtra != null)
                {
                    subscribeExtra(that.Value, lastValue, () => result.Value = get(that.Value));
                }
                lastValue = Value;
            };
            return(result);
        }