mapWithModel<ParentModel, ChildModel, ChildMsg, ParentMsg> static method
Map a subscription from a child model/message pair to a parent model/message pair.
Use this when composing nested MVU components where both the model and message types differ between parent and child.
msgMapper converts a child message to a parent message.
modelMapper extracts the child model from the current parent model,
so the child subscription always receives a fresh, correctly-scoped model.
Implementation
static Sub<ParentModel, ParentMsg>
mapWithModel<ParentModel, ChildModel, ChildMsg, ParentMsg>(
String idPrefix,
Sub<ChildModel, ChildMsg> sub,
ParentMsg Function(ChildMsg) msgMapper,
ChildModel Function(ParentModel) modelMapper) =>
Sub(sub._subs.map((inner) {
final (subId, subscribe) = inner;
return (
[idPrefix, ...subId],
(SubHandler<ParentModel, ParentMsg> handler) => subscribe(
SubHandler<ChildModel, ChildMsg>(
(ChildMsg innerMsg) =>
handler.dispatch(msgMapper(innerMsg)),
() => modelMapper(handler.model)))
);
}).toList());