undoable()
undoable(
execute,undo): UndoableCommand
Creates an undoable command from an execute/undo pair.
Parametersβ
execute: Commandβ
The action to perform
undo: Commandβ
The action that reverses execute
Returns: UndoableCommandβ
An UndoableCommand
Sinceβ
2.4.0
Exampleβ
const items: string[] = [];
const addItem = (item: string) => undoable(
() => items.push(item),
() => items.pop(),
);
const cmd = addItem("hello");
cmd.execute(); // items = ["hello"]
cmd.undo(); // items = []
UndoableCommandβ
An UndoableCommand pairs an execute action with its inverse. Replaces the GoF Command interface + ConcreteCommand classes.
Sinceβ
2.4.0
Propertiesβ
execute: Commandβ
undoβ
readonlyundo: Command
Command()β
Command = () =>
void
A Command is a thunk - a deferred action with no arguments. In FP, this IS the pattern: a function is already a reifiable value.
Returns: voidβ
Sinceβ
2.4.0