map<Model, Inner, Msg> static method

Sub<Model, Msg> map<Model, Inner, Msg>(
  1. String idPrefix,
  2. Sub<Model, Inner> sub,
  3. Msg f(
    1. Inner
    )
)

Map a subscription from one message type to another, keeping the same model.

Implementation

static Sub<Model, Msg> map<Model, Inner, Msg>(
        String idPrefix, Sub<Model, Inner> sub, Msg Function(Inner) f) =>
    Sub(sub._subs.map((inner) {
      final (subId, subscribe) = inner;
      return (
        [idPrefix, ...subId],
        (SubHandler<Model, Msg> handler) => subscribe(
            SubHandler<Model, Inner>(
                (Inner innerMsg) => handler.dispatch(f(innerMsg)),
                () => handler.model))
      );
    }).toList());