update method

  1. @override
(ListModel, 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
(ListModel, Cmd?) update(Msg msg) {
  final cmds = <Cmd>[];

  if (msg is KeyMsg) {
    if (keyMatches(msg.key, [keyMap.forceQuit])) {
      return (this, Cmd.quit());
    }
  }

  if (msg is FilterMatchesMsg) {
    _filteredItems = msg.matches;
    return (this, null);
  }

  if (msg is SpinnerTickMsg) {
    final (newSpinner, cmd) = spinner.update(msg);
    spinner = newSpinner;
    if (_showSpinner && cmd != null) cmds.add(cmd);
  }

  if (msg is StatusMessageTimeoutMsg) {
    hideStatusMessage();
  }

  if (_filterState == FilterState.filtering) {
    final cmd = _handleFiltering(msg);
    if (cmd != null) cmds.add(cmd);
  } else {
    final cmd = _handleBrowsing(msg);
    if (cmd != null) cmds.add(cmd);
  }

  return (this, cmds.isNotEmpty ? Cmd.batch(cmds) : null);
}