update method

  1. @override
(MultiProgressModel, Cmd?) update(
  1. Msg msg
)
override

Updates the component state in response to a message.

Returns the updated component (often this) and an optional command.

Implementation

@override
(MultiProgressModel, Cmd?) update(Msg msg) {
  if (msg is! ProgressFrameMsg) return (this, null);

  final cmds = <Cmd>[];
  final newBars = Map<String, ProgressModel>.from(bars);
  var changed = false;

  for (final entry in bars.entries) {
    final (newBar, cmd) = entry.value.update(msg);
    if (newBar != entry.value) {
      newBars[entry.key] = newBar;
      changed = true;
    }
    if (cmd != null) cmds.add(cmd);
  }

  if (!changed && cmds.isEmpty) return (this, null);
  return (
    MultiProgressModel(bars: newBars, width: width),
    cmds.isEmpty ? null : Cmd.batch(cmds),
  );
}