anyInBoundsAndUpdate method

(Model, Cmd?) anyInBoundsAndUpdate(
  1. Model model,
  2. MouseMsg mouse
)

Sends a ZoneInBoundsMsg to the model for each zone that contains the mouse position.

Returns the final model state and a batch of all commands.

Example

@override
(Model, Cmd?) update(Msg msg) {
  if (msg is MouseMsg) {
    return zone.anyInBoundsAndUpdate(this, msg);
  }
  // Handle ZoneInBoundsMsg
  if (msg is ZoneInBoundsMsg) {
    return handleZoneClick(msg.zone, msg.event);
  }
  return (this, null);
}

Implementation

(Model, Cmd?) anyInBoundsAndUpdate(Model model, MouseMsg mouse) {
  final zones = findInBounds(mouse);
  if (zones.isEmpty) return (model, null);

  final cmds = <Cmd>[];
  var currentModel = model;

  for (final zone in zones) {
    final (newModel, cmd) = currentModel.update(
      ZoneInBoundsMsg(zone: zone, event: mouse),
    );
    currentModel = newModel;
    if (cmd != null) cmds.add(cmd);
  }

  return (currentModel, cmds.isEmpty ? null : Cmd.batch(cmds));
}