Prism<GlobalAction, LocalAction, ID> typedef

Prism<GlobalAction, LocalAction, ID> = ({GlobalAction Function(ID id, LocalAction localAction) embed, (ID, LocalAction)? Function(GlobalAction action) extract})

A keyed variant of ActionLens for routing actions to elements in a collection by ID.

Used with ForEachIterableReducer.forEach to dispatch actions to individual elements in a list or map.

  • extract returns (id, localAction) if the global action targets a collection element, or null to skip.
  • embed wraps a local action with its element ID into a global action.
Prism<AppAction, ItemAction, String> itemPrism = (
  extract: (a) => switch (a) { EditItem(id, a) => (id, a), _ => null },
  embed: (id, a) => AppAction.editItem(id, a),
);

Implementation

typedef Prism<GlobalAction, LocalAction, ID> = ({
  (ID, LocalAction)? Function(GlobalAction action) extract,
  GlobalAction Function(ID id, LocalAction localAction) embed,
});