UndoableCommand<T extends JState> class abstract

Command pattern implementation for undo/redo.

This is an alternative approach to the mixin-based undo/redo. Use this when you need more control over what gets undone/redone.

Example:

class IncrementCommand extends UndoableCommand<CounterState> {
  final int amount;

  IncrementCommand(this.amount);

  @override
  CounterState execute(CounterState state) {
    return state.copyWith(counter: state.counter + amount);
  }

  @override
  CounterState undo(CounterState state) {
    return state.copyWith(counter: state.counter - amount);
  }
}

// Usage in intent
final command = IncrementCommand(1);
final newState = commandHistory.execute(state, command);
update((_) => newState);

Constructors

UndoableCommand()

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

execute(T state) → T
Executes the command and returns the new state.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
redo(T state) → T
Optional: Redo the command (by default, calls execute again).
toString() → String
A string representation of this object.
inherited
undo(T state) → T
Undoes the command and returns the previous state.

Operators

operator ==(Object other) → bool
The equality operator.
inherited