public static ReactiveCommandWithHistory <TParam, TResult> CreateWithHistory <TParam, TResult>( string commandKey, Func <TParam, TResult, TResult> execute, Func <TParam, TResult, TResult> discard, HistoryContext context, IObservable <bool>?canExecute = null, IScheduler?outputScheduler = null) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (execute == null) { throw new ArgumentNullException(nameof(execute)); } if (discard == null) { throw new ArgumentNullException(nameof(discard)); } return(new ReactiveCommandWithHistory <TParam, TResult>(commandKey, (param, result) => Observable.Create <TResult>( observer => { observer.OnNext(execute(param, result)); observer.OnCompleted(); return new CompositeDisposable(); }), (param, result) => Observable.Create <TResult>( observer => { observer.OnNext(discard(param, result)); observer.OnCompleted(); return new CompositeDisposable(); }), context, canExecute ?? Observables.True, outputScheduler ?? RxApp.MainThreadScheduler)); }
internal static HistoryContext GetContext(IHistory history, IScheduler?outputScheduler = null) { if (history == null) { throw new ArgumentNullException(nameof(history)); } if (history.Id == null) { throw new ArgumentNullException(nameof(history.Id)); } var context = Locator.Current.GetService <HistoryContext>(history.Id); if (context != null) { return(context); } context = new HistoryContext(history, outputScheduler ?? RxApp.MainThreadScheduler); Locator.CurrentMutable.RegisterConstant(context, history.Id); return(context); }
internal ReactiveCommandWithHistory( string commandKey, Func <TParam, TResult, IObservable <TResult> > execute, Func <TParam, TResult, IObservable <TResult> > discard, HistoryContext context, IObservable <bool> canExecute, IScheduler outputScheduler) { if (execute == null) { throw new ArgumentNullException(nameof(execute)); } if (discard == null) { throw new ArgumentNullException(nameof(discard)); } if (canExecute == null) { throw new ArgumentNullException(nameof(canExecute)); } if (outputScheduler == null) { throw new ArgumentNullException(nameof(outputScheduler)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } if (commandKey == null) { throw new ArgumentNullException(nameof(commandKey)); } var command = Locator.Current.GetService <IReactiveCommandWithHistory>(commandKey); if (command != null) { throw new ArgumentException($"Command with key '{commandKey}' already was registered."); } History = context; _discard = ReactiveCommand.CreateFromObservable <HistoryEntry, TResult>( entry => discard((TParam)entry.Parameter, (TResult)entry.Result), outputScheduler: outputScheduler); var canActuallyExecute = context .CanRecord .CombineLatest(canExecute, (recordable, executable) => recordable && executable); _execute = ReactiveCommand.CreateFromObservable <HistoryEntry, TResult>( entry => execute((TParam)entry.Parameter, (TResult)entry.Result), canActuallyExecute, outputScheduler); History = context; _commandKey = commandKey; _canExecuteSubscription = canExecute.Subscribe(OnCanExecuteChanged); Locator.CurrentMutable.RegisterConstant <IReactiveCommandWithHistory>(this, commandKey); }