update method

  1. @override
(ViewComponent, 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
(ViewComponent, Cmd?) update(Msg msg) {
  return switch (msg) {
    ProgressBarSetMsg(:final id, :final current, :final total)
        when id == this.id =>
      (copyWith(current: current, total: total), null),
    ProgressBarAdvanceMsg(:final id, :final step) when id == this.id => (
      copyWith(
        current: total > 0
            ? (current + step).clamp(0, total)
            : current + step,
      ),
      null,
    ),
    _ => (this, null),
  };
}