Skip to content

High order reducer that provides undo/redo functionality to redux state containers.

Notifications You must be signed in to change notification settings

mariusz-ba/mb-redux-undo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mb-redux-undo

mb-redux-undo is a library that provides undo and redo functionality to redux state containers.

Installation

To install the stable version

npm install --save mb-redux-undo

Usage

To make Your reducer undoable you just have to wrap it in high order reducer that is provided by mb-redux-undo:

const { createStore } = require('redux');
const { undoable, actions } = require('mb-redux-undo');

const createStore(
  undoable(reducer)
)

At this point an additional functionality will be added to your reducer. The state shape will change to:

{
  past: [],
  present: ... your base reducers state,
  future: []
}

Every time a new action is dispatched the current state will be added to the end of past array so it could be restored later on by dispatchin undo action:

const { actions } = require('mb-redux-undo');

store.dispatch({ type: actions.undo });

The future array is storing all undone elements from past array and they can be restored by dispatchin redo action:

const { actions } = require('mb-redux-undo');

store.dispatch({ type: actions.redo });

Notice that after dispatching any other action that isn't a undo or redo action the future array will be cleared.

About

High order reducer that provides undo/redo functionality to redux state containers.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published