0.1.7 • Published 4 years ago

patched-undo-peasy v0.1.7

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Undo/Redo support for easy peasy.

patched-undo-peasy depends on an easy peasy fork. (but modifying undo-peasy to depend on stock easy-peasy should be straightforward.)

Usage

  1. Attach undoRedoMiddleWare in createStore.
    const store = createStore(appModel, {
      middleware: [undoRedo()],
    });
  2. If using typescript, the root application model should extend WithUndo. WithUndo will add types for undo actions and undo history to your root model.
    ```
      interface Model extends WithUndo {
        count: number;
        increment: Action<Model>;
      }
    ```
  3. Wrap the root application instance in undoable. undoable will add types for undo actions and undo history to your root model.
    ```
    const appModel: Model = undoable({
      count: 0,
      increment: action((state) => {
        state.count++;
      }),
    });
    ```
  4. Profit
    const undoAction = useStoreActions((actions) => actions.undoUndo);

Supported Actions

  • undoUndo - restore state to the most recently saved version.
  • undoRedo - restore state to the most recently undone version.
  • undoSave - save current application state to undo history. undoSave is generated automatically by the middleware, but in rare cases it's useful to save manually.
  • undoReset - erases saved undo/redo history and saves the current state.

Configuration

The undoRedo() middleware function accepts an optional configuration object.

  • noSaveActions - a function that tells undoRedo to not save certain actions to undo/redo history.
  • noSaveKeys - a function tthat tells undoRedo not to save certain keys inside the state model to undo/redo history. e.g. view state in the model.
0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago