RxCommandListener<TParam, TResult> constructor

RxCommandListener<TParam, TResult>(
  1. RxCommand<TParam, TResult> command, {
  2. void onValue(
    1. TResult? value
    )?,
  3. void onIsBusyChange(
    1. bool isBusy
    )?,
  4. void onIsBusy()?,
  5. void onNotBusy()?,
  6. void onError(
    1. dynamic ex
    )?,
  7. void onCanExecuteChange(
    1. bool state
    )?,
  8. void onResult(
    1. CommandResult<TParam, TResult> result
    )?,
  9. 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?.call() : this.onNotBusy?.call();
      });
    }
  } 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?.call() : this.onNotBusy?.call());
      }
    }
  }
  if (onError != null) {
    errorSubscription = command.thrownExceptions.listen(onError);
  }

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