undoableState()
undoableState<
S>(execute,undo): UndoableStateCommand<S>
Creates an undoable state command from an execute/undo pair.
Unlike undoable (imperative thunks), these are pure state transforms.
Type Parametersβ
S: Sβ
Parametersβ
execute: StateCommand<S>β
Pure function that produces the next state
undo: StateCommand<S>β
Pure function that reverses execute
Returns: UndoableStateCommand<S>β
An UndoableStateCommand
Sinceβ
2.5.0
Exampleβ
interface Counter { value: number }
const increment = undoableState`<Counter>`(
(s) => ({ ...s, value: s.value + 1 }),
(s) => ({ ...s, value: s.value - 1 }),
);
UndoableStateCommand<S>β
An undoable state command pairs a forward transform with its inverse. Both are pure functions from state to state.
Sinceβ
2.5.0
Type Parametersβ
S: Sβ
Propertiesβ
execute: StateCommand<S>β
undoβ
readonlyundo: StateCommand<S>
StateCommand()<S>β
StateCommand<
S> = (state) =>S
A state command is a pure function: takes current state, returns next state. No mutation, no side effects. The stack manages the state for you.
Type Parametersβ
S: Sβ
Parametersβ
state: Sβ
Returns: Sβ
Sinceβ
2.5.0