command_history 0.2.0
command_history: ^0.2.0 copied to clipboard
Generic immutable undo/redo ring for Dart. Type-safe CommandHistory<S> with Command<S> — maxSize cap, undo/redo labels, value equality, no Flutter dependency.
0.2.0 #
Breaking change: Command<S> is now abstract class (was abstract interface class).
Change implements Command<S> to extends Command<S> in your command classes.
- Immutable stacks:
undoStack/redoStackare now exposed viaUnmodifiableListView— any attempt to mutate them throwsUnsupportedError.replaceCurrentwith mappers usesList.unmodifiable()for the same guarantee. - Command labels:
CommandgainsString? get label => null. Override it to driveCommandHistory.undoLabel/CommandHistory.redoLabel(e.g."Undo Paint Stroke"). - Bounded history:
CommandHistory.initial(state, maxSize: N)caps undo depth; oldest entry is dropped on overflow. - Value equality:
==andhashCodecompare state + both stacks element-by-element, enabling use in Riverpod/BLoC state containers without spurious rebuilds and asMapkeys. clearHistory(): resets both stacks while preservingstateandmaxSize— useful after a save-point event.toString():CommandHistory(state: 5, undo: 2, redo: 0)for debugger output.- Tests: 26 → 58.
0.1.0 #
- Initial extraction from sdraw monorepo.
Command<S>: abstract interface for reversible state operations.CommandHistory<S>: generic immutable undo/redo ring.- No Flutter dependency — pure Dart.