RxCommandListener<TParam, TResult> constructor

RxCommandListener<TParam, TResult>(RxCommand<TParam, TResult> command, { void onValue(TResult value), void onIsBusyChange(bool isBusy), void onIsBusy(), void onNotBusy(), void onError(dynamic ex), void onCanExecuteChange(bool state), void onResult(CommandResult<TResult> result), Duration debounceDuration })

Implementation

RxCommandListener(
  this.command, {
  this.onValue,
  this.onIsBusyChange,
  this.onIsBusy,
  this.onNotBusy,
  this.onError,
  this.onCanExecuteChange,
  this.onResult,
  this.debounceDuration,
}) {
  if (debounceDuration == null) {
    if (onValue != null) {
      valueSubscription = command.listen(onValue);
    }

    if (onResult != null) {
      resultsSubscription = command.results.listen(onResult);
    }

    if (onIsBusyChange != null) {
      busyChangeSubscription = command.isExecuting.listen(onIsBusyChange);
    }
    if (onIsBusy != null || onNotBusy != null) {
      busySubscription = command.isExecuting.listen((isBusy) {
        return isBusy ? this?.onIsBusy() : this?.onNotBusy();
      });
    }
  } else {
    if (onValue != null) {
      valueSubscription = command.debounceTime(debounceDuration).listen(onValue);
      if (onResult != null && debounceDuration != null) {
        resultsSubscription = command.results.debounceTime(debounceDuration).listen(onResult);
      }

      if (onIsBusyChange != null) {
        busyChangeSubscription = command.isExecuting.debounceTime(debounceDuration).listen(onIsBusyChange);
      }

      if (onIsBusy != null && onNotBusy != null) {
        busySubscription = command.isExecuting
            .debounceTime(debounceDuration)
            .listen((isBusy) => isBusy ? this?.onIsBusy : this.onNotBusy);
      }
    }
  }
  if (onError != null) {
    errorSubscription = command.thrownExceptions.listen(onError);
  }

  if (onCanExecuteChange != null) {
    canExecuteStateSubscription = command.canExecute.listen(onCanExecuteChange);
  }
}