fromStream<Msg, S> static method

SubItem<Msg> fromStream<Msg, S>(
  1. SubscriptionId id,
  2. Stream<S> stream,
  3. Msg? streamObjectToMsg(
    1. S
    )
)

Creates a subscription from a stream, transforming the stream objects to messages.

Implementation

static SubItem<Msg> fromStream<Msg, S>(SubscriptionId id, Stream<S> stream,
        Msg? Function(S) streamObjectToMsg) =>
    (
      id,
      (dispatch) => stream.listen((s) {
            if (streamObjectToMsg(s) case Msg msg) {
              dispatch(msg);
            }
          }).cancel
    );