RxCommand<TParam, TResult> constructor
RxCommand<TParam, TResult> ()
Implementation
RxCommand(
this._resultsSubject,
Stream<bool?>? restriction,
this._includeLastResultInCommandResults,
this._resultSubjectIsBehaviourSubject,
this.lastResult,
bool noReturnValue,
String? debugName,
bool noParamValue)
: _noReturnValue = noReturnValue,
_noParamValue = noParamValue,
_debugName = debugName,
super(_resultsSubject) {
_commandResultsSubject = _resultSubjectIsBehaviourSubject
? BehaviorSubject<CommandResult<TParam, TResult>>()
: PublishSubject<CommandResult<TParam, TResult>>();
_commandResultsSubject.where((x) => x.hasError).listen(
(x) => _thrownExceptionsSubject.add(CommandError(x.paramData, x.error)),
onError: (x) {});
_commandResultsSubject.listen((x) => _isExecutingSubject.add(x.isExecuting),
onError: (x) {});
final _canExecuteParam = restriction == null
? Stream<bool>.value(true)
: restriction.handleError((error) {
if (error is Exception) {
_thrownExceptionsSubject.add(CommandError(null, error));
}
}).distinct();
_canExecuteParam.listen((canExecute) {
_canExecute = (canExecute ?? false) && (!_isRunning);
_executionLocked = !(canExecute ?? false);
_canExecuteSubject.add(_canExecute);
});
}