watchStatus<T> static method

LxWorker<LxStatus<T>> watchStatus<T>(
  1. LxReactive<LxStatus<T>> source, {
  2. void onIdle()?,
  3. void onWaiting()?,
  4. void onSuccess(
    1. T value
    )?,
  5. void onError(
    1. Object error
    )?,
  6. dynamic onProcessingError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})

Watches an async source and triggers callbacks for specific state transitions.

Implementation

static LxWorker<LxStatus<T>> watchStatus<T>(
  LxReactive<LxStatus<T>> source, {
  void Function()? onIdle,
  void Function()? onWaiting,
  void Function(T value)? onSuccess,
  void Function(Object error)? onError,
  Function(Object error, StackTrace stackTrace)? onProcessingError,
}) {
  return LxWorker<LxStatus<T>>(
    source,
    (status) {
      if (status is LxIdle<T>) {
        return onIdle?.call();
      } else if (status is LxWaiting<T>) {
        return onWaiting?.call();
      } else if (status is LxSuccess<T>) {
        return onSuccess?.call(status.value);
      } else if (status is LxError<T>) {
        return onError?.call(status.error);
      }
    },
    onProcessingError: onProcessingError,
  );
}