v2.0.0 - A rethink
Up to this point, the history adapter has always tracked changes with JSON Patches, a data format that looks something like the below:
{
undo: [
{
op: "replace",
path: ["present", "value"],
value: 0,
},
],
redo: [
{
op: "replace",
path: ["present", "value"],
value: 1,
},
],
}However, if your changes are more complex than your state shape, these can end up being pretty large.
Packages like redux undo instead store the entire version of state, and flip back and forth as needed.
In 2.0, createHistoryAdapter will now use this approach, and a createPatchHistoryAdapter version is available to use the previous behaviour.
Breaking changes
createHistoryAdapternow uses entire copies of state, rather than patches of changescreatePatchHistoryAdapteravailable for previous behaviour- similarly,
HistoryStatetype no longer uses patches, whereasPatchHistoryStatedoes
- Second argument for
undoablecan no longer beisUndoablefunction - needs to be config object
Other changes
- Build is no longer minified, allowing for better minification in the user's bundler