Skip to content

Commit a961662

Browse files
committed
Fix incorrect UndoableCommand function signature
Corrected createUndoable signature: - func receives UndoStack<TUndoState>, not TUndoState value - undo is UndoFn<TUndoState, TResult> with signature (UndoStack, Object? reason) - Updated descriptions to reflect actual API The function works with the undo stack directly to push/pop state snapshots, not individual state values. Verified against source: command_it.dart:1636 and undoable_command.dart:42-43
1 parent 8c5abad commit a961662

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

docs/documentation/command_it/command_types.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ Undoable commands extend async commands with undo capability. They maintain an `
134134

135135
```dart
136136
static UndoableCommand<TParam, TResult, TUndoState> createUndoable<TParam, TResult, TUndoState>(
137-
Future<TResult> Function(TParam param, TUndoState undoState) func,
138-
UndoHandler<TParam, TUndoState> undo,
137+
Future<TResult> Function(TParam param, UndoStack<TUndoState> undoStack) func,
138+
UndoFn<TUndoState, TResult> undo,
139139
TResult initialValue, {
140140
ValueListenable<bool>? restriction,
141141
RunInsteadHandler<TParam>? ifRestrictedRunInstead,
@@ -150,13 +150,16 @@ static UndoableCommand<TParam, TResult, TUndoState> createUndoable<TParam, TResu
150150

151151
**Undoable-specific parameters:**
152152

153-
- **`func`** - Your async function that receives **TWO parameters**: the command parameter (`TParam`) AND the undo state (`TUndoState`) returned by the undo handler
153+
- **`func`** - Your async function that receives **TWO parameters**: the command parameter (`TParam`) AND the undo stack (`UndoStack<TUndoState>`) where you push state snapshots
154154

155-
- **`undo`** - Handler function called before execution to capture the state snapshot:
155+
- **`undo`** - Handler function called to perform the undo operation:
156156
```dart
157-
typedef UndoHandler<TParam, TUndoState> = TUndoState Function(TParam? param)
157+
typedef UndoFn<TUndoState, TResult> = FutureOr<TResult> Function(
158+
UndoStack<TUndoState> undoStack,
159+
Object? reason
160+
)
158161
```
159-
Return the state needed to undo this operation (e.g., the old value before modification)
162+
Pop state from the stack and restore it. Called when user manually undos or when `undoOnExecutionFailure: true` and execution fails
160163

161164
- **`undoOnExecutionFailure`** - When `true`, automatically calls the undo handler and restores state if the command fails. Perfect for optimistic updates that need rollback on error
162165

0 commit comments

Comments
 (0)