RxCommand<TParam, TResult> constructor

RxCommand<TParam, TResult>(Subject<TResult> _resultsSubject, Observable<bool> canExecuteRestriction, bool _emitLastResult, bool _resultSubjectIsBehaviourSubject, TResult lastResult)

Implementation

RxCommand(this._resultsSubject, Observable<bool> canExecuteRestriction, this._emitLastResult,
    this._resultSubjectIsBehaviourSubject, this.lastResult)
    : super(_resultsSubject) {
  _commandResultsSubject = _resultSubjectIsBehaviourSubject
      ? new BehaviorSubject<CommandResult<TResult>>()
      : new PublishSubject<CommandResult<TResult>>();

  _commandResultsSubject.where((x) => x.hasError).listen((x) => _thrownExceptionsSubject.add(x.error));

  _commandResultsSubject.listen((x) => _isExecutingSubject.add(x.isExecuting));

  final _canExecuteParam = canExecuteRestriction == null
      ? new Observable<bool>.just(true)
      : canExecuteRestriction.handleError((error) {
          if (error is Exception) {
            _thrownExceptionsSubject.add(error);
          }
        }).distinct();

  _canExecuteParam.listen((canExecute) {
    _canExecute = canExecute && (!_isRunning);
    _executionLocked = !canExecute;
    _canExecuteSubject.add(_canExecute);
  });
}