fromStream<Model, Msg, S> static method

SubItem<Model, Msg> fromStream<Model, 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<Model, Msg> fromStream<Model, Msg, S>(SubscriptionId id,
        Stream<S> stream, Msg? Function(S) streamObjectToMsg) =>
    (
      id,
      (handler) => stream.listen((s) {
            if (streamObjectToMsg(s) case Msg msg) {
              handler(msg);
            }
          }).cancel
    );