Command<TParam, TResult> constructor
Command<TParam, TResult> ()
Implementation
Command(
TResult initialValue,
ValueListenable<bool>? restriction,
bool includeLastResultInCommandResults,
bool noReturnValue,
bool catchAlways,
String? debugName,
bool noParamValue)
: _noReturnValue = noReturnValue,
_noParamValue = noParamValue,
_includeLastResultInCommandResults = includeLastResultInCommandResults,
_catchAlways = catchAlways,
_debugName = debugName,
super(initialValue) {
_commandResult =
_ListenerCountingValueNotifier<CommandResult<TParam?, TResult>>(
CommandResult.data(null, initialValue));
/// forward error states to the `thrownExceptions` Listenable
_commandResult.where((x) => x.hasError).listen((x, _) {
_thrownExceptions.value = CommandError<TParam>(x.paramData, x.error!);
_thrownExceptions.notifyListeners();
});
/// forward busy states to the `isExecuting` Listenable
_commandResult.listen((x, _) => _isExecuting.value = x.isExecuting);
/// Merge the external execution restricting with the internal
/// isExecuting which also blocks execution if true
_canExecute = (restriction == null)
? _isExecuting.map((val) => !val) as ValueNotifier<bool>
: restriction.combineLatest<bool, bool>(_isExecuting,
(restriction, isExecuting) => restriction && !isExecuting)
as ValueNotifier<bool>;
}