addObservable<T> method

Disposable addObservable<T>(
  1. Observable<T> observable, {
  2. S next(
    1. S state,
    2. T value
    )?,
  3. S error(
    1. S state,
    2. Object error,
    3. StackTrace stackTrace
    )?,
  4. S complete(
    1. S state
    )?,
  5. bool ignoreErrors = false,
})

Adds an observable that asynchronously contributes to the state through next, error and complete reducers. These functions receive the current state and the events of the Observer to produce a new state.

Implementation

Disposable addObservable<T>(
  Observable<T> observable, {
  S Function(S state, T value)? next,
  S Function(S state, Object error, StackTrace stackTrace)? error,
  S Function(S state)? complete,
  bool ignoreErrors = false,
}) => observable.subscribe(
  Observer(
    next: next == null
        ? null
        : (value) => update((state) => next(state, value)),
    error: error == null
        ? null
        : (exception, stackTrace) =>
              update((state) => error(state, exception, stackTrace)),
    complete: complete == null ? null : () => update(complete),
    ignoreErrors: ignoreErrors,
  ),
);