@syncstate/history is a SyncState plugin which provides Undo and Redo functionality out of the box.
You have the option of inserting breakpoints in the history using which you can undo till a specific point in state.
By default, this plugin will automatically work for the root document which means any change to the document is recorded and performing undo or redo actions will work with those changes.
If you want to maintain separate undo/redo stack for different parts of the document, you can use
history.enable for a path inside document.
- SyncState stores
inversePatcheswhich means the opposite of
patchesgenerated against user actions. An inversePatch can be applied to reverse the operation of a corresponding patch.
- SyncState history plugin adds a middleware to SyncState's internal Redux store and listens to changes and stores patches and inversePatches in an undo stack. It also maintains a redo stack.
- To Undo and Redo, it simply picks up the patches from Undo and Redo stacks and applied them to SyncState store.
- It doesn't replace with the entire snapshot of the app. Instead it applies a patch on the document from the Undo / Redo stack.