execute method
- T currentState,
- UndoableCommand<
T> command
Executes a command and adds it to history only if its state changes. A throwing command leaves both stacks untouched. Commands must return new immutable states; external side effects cannot be rolled back here.
Implementation
T execute(T currentState, UndoableCommand<T> command) {
final next = command.execute(currentState);
if (next == currentState) return next;
_undoStack.add(command);
if (_undoStack.length > maxSize) {
_undoStack.removeAt(0);
}
_redoStack.clear();
return next;
}