コード例 #1
0
 private void SetValue(T value)
 {
     LatestValue = value;
     ValidationTrigger.OnNext(value);
     Source.OnNext(value);
     RaiseEventScheduler.Schedule(() => PropertyChanged?.Invoke(this, SingletonPropertyChangedEventArgs.Value));
 }
コード例 #2
0
    private void OnNextAndRaiseValueChanged(ref T value)
    {
        // call source.OnNext
        var node = _root;

        while (node != null)
        {
            node.OnNext(value);
            node = node.Next;
        }

        RaiseEventScheduler.Schedule(() => PropertyChanged?.Invoke(this, SingletonPropertyChangedEventArgs.Value));
    }
コード例 #3
0
    /// <summary>
    /// <para>Set INotifyDataErrorInfo's asynchronous validation, return value is self.</para>
    /// </summary>
    /// <param name="validator">If success return IO&lt;null&gt;, failure return IO&lt;IEnumerable&gt;(Errors).</param>
    /// <returns>Self.</returns>
    public ReactiveProperty <T> SetValidateNotifyError(Func <IObservable <T>, IObservable <IEnumerable?> > validator)
    {
        ValidatorStore.Value.Add(validator);     //--- cache validation functions
        var validators = ValidatorStore.Value
                         .Select(x => x(IsIgnoreInitialValidationError ? ValidationTrigger : ValidationTrigger.StartWith(LatestValue)))
                         .ToArray(); //--- use copy

        ValidateNotifyErrorSubscription.Disposable = Observable
                                                     .CombineLatest(validators)
                                                     .Select(xs =>
        {
            if (xs.Count == 0)
            {
                return(null);
            }

            if (xs.All(x => x == null))
            {
                return(null);
            }

            var strings = xs
                          .Where(x => x != null)
                          .OfType <string>();
            var others = xs
                         .Where(x => x is not string)
                         .Where(x => x != null)
                         .SelectMany(x => x !.Cast <object?>());
            return(strings.Concat(others));
        })
                                                     .Subscribe(x =>
        {
            var prevHasErrors    = HasErrors;
            CurrentErrors        = x;
            var currentHasErrors = HasErrors;
            var handler          = ErrorsChanged;
            if (handler != null)
            {
                RaiseEventScheduler.Schedule(() => handler(this, SingletonDataErrorsChangedEventArgs.Value));
            }

            var propertyChangedHandler = PropertyChanged;
            if (prevHasErrors != currentHasErrors && propertyChangedHandler != null)
            {
                RaiseEventScheduler.Schedule(() => propertyChangedHandler(this, SingletonPropertyChangedEventArgs.HasErrors));
            }

            ErrorsTrigger.Value.OnNext(x);
        });
        return(this);
    }
コード例 #4
0
        /// <summary>
        ///     <para>Set INotifyDataErrorInfo's asynchronous validation, return value is self.</para>
        /// </summary>
        /// <param name="validator">If success return IO&lt;null&gt;, failure return IO&lt;IEnumerable&gt;(Errors).</param>
        /// <returns>Self.</returns>
        public WeakReactiveProperty <T> SetValidateNotifyError(Func <IObservable <T>, IObservable <IEnumerable> > validator)
        {
            ValidatorStore.Value.Add(validator); //--- cache validation functions
            var validators = ValidatorStore.Value
                             .Select(x => x(ValidationTrigger.StartWith(LatestValue)))
                             .ToArray(); //--- use copy

            ValidateNotifyErrorSubscription.Disposable
                = Observable.CombineLatest(validators)
                  .Select(xs =>
            {
                if (xs.Count == 0)
                {
                    return(null);
                }
                if (xs.All(x => x == null))
                {
                    return(null);
                }

                var strings = xs
                              .OfType <string>()
                              .Where(x => x != null);
                var others = xs
                             .Where(x => !(x is string))
                             .Where(x => x != null)
                             .SelectMany(x => x.Cast <object>());
                return(strings.Concat(others));
            })
                  .WeakSubscribe(new AnonymousObserver <IEnumerable <object> >(x =>
            {
                CurrentErrors = x;
                var handler   = ErrorsChanged;
                if (handler != null)
                {
                    RaiseEventScheduler.Schedule(
                        () => handler(this, SingletonDataErrorsChangedEventArgs.Value));
                }
                ErrorsTrigger.Value.OnNext(x);
            }));
            return(this);
        }