addStream<T> method

StreamSubscription<T> addStream<T>(
  1. Stream<T> stream, {
  2. S onData(
    1. S state,
    2. T event
    )?,
  3. S onError(
    1. S state,
    2. Object error,
    3. StackTrace stackTrace
    )?,
  4. S onDone(
    1. S state
    )?,
  5. bool? cancelOnError,
})

Adds a stream that asynchronously contributes to the state through onData, onError and onDone reducers. These functions receive the current state and the events of the Stream to produce a new state.

Implementation

StreamSubscription<T> addStream<T>(
  Stream<T> stream, {
  S Function(S state, T event)? onData,
  S Function(S state, Object error, StackTrace stackTrace)? onError,
  S Function(S state)? onDone,
  bool? cancelOnError,
}) =>
    stream.listen(
        onData == null
            ? null
            : (event) => update((state) => onData(state, event)),
        onError: onError == null
            ? null
            : (Object error, StackTrace stackTrace) =>
                update((state) => onError(state, error, stackTrace)),
        onDone: onDone == null ? null : () => update(onDone),
        cancelOnError: cancelOnError);