AbstractReadonlycanEmits whether any states are available for redo().
ReadonlycanEmits whether any states are available for undo().
ProtectedmaxThe maximum size of the history before discarding the oldest state. 0 means no limit.
ReadonlystateEmits the current undo state that was most recently pushed or applied. Calls to undo will apply the state before this in the stack, and redo will apply the state after this.
Protected ReadonlystoreReturns a view of the internal undo stack, from oldest to newest. Note that this contains states that would be applied by calls to both .undo() and .redo.
Protected AbstractapplyReset the store to the given state.
The undoOrRedo and stateToOverwrite parameters can be useful e.g. if a scroll position is kept in the undo state. In such a case you want to change the scrolling so the user can see what just changed by undoing/redoing. To do that, set the scoll to what it was in stateToOverwrite when undoing, and to what it is in stateToApply when redoing.
Drops the state from the internal undo stack that would be applied by a call to .undo(). This is useful e.g. if making multiple changes in a row that should be collapsed into a single undo state: call this first before pushing the new version.
Protected AbstractextractReturn the information needed to reconstruct the given state. This will be passed to applyUndoState() when the store should be reset to this state.
ProtectedisEach time a state is added to the history, this method will be called to determine whether the oldest state should be dropped. Override to implement more complex logic than the simple maxDepth.
Add the current state to the undo history. Any states that could be reached using redo() are discarded.
Discard all history and push the current state.
ProtectedshouldUsed to determine whether .pushCurrentState() actually does anything. Override this e.g. to prevent pushing a duplicate undo state using something like this:
protected shouldPush(state: UndoStateType) {
return equal(state, this.currentUndoState);
}
Assists in creating undo/redo functionality. Below is a minimal undo service.
Then in your app you can simply call
service.pushCurrentState()after any user interaction to preserve it in the undo stack.