Skip to content

v2.0.0 - A rethink

Compare
Choose a tag to compare
@EskiMojo14 EskiMojo14 released this 30 May 17:02
· 67 commits to main since this release

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

  • createHistoryAdapter now uses entire copies of state, rather than patches of changes
    • createPatchHistoryAdapter available for previous behaviour
    • similarly, HistoryState type no longer uses patches, whereas PatchHistoryState does
  • Second argument for undoable can no longer be isUndoable function - needs to be config object

Other changes

  • Build is no longer minified, allowing for better minification in the user's bundler