@alcadica/state-manager-history
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

state-manager-history

branch status
master Build Status
dev Build Status

Install

npm i --save @alcadica/{state-manager,state-manager-history}

Usage

With this middleware you can rollback your store at a previous state.

Example:

import createStore from '@alcadica/state-manager';
import StoreHistory from '@alcadica/state-manager-history';

const store = createStore({ foo: 0 });
const config = { maxRecords: 25 };

store.use(StoreHistory(config));

const increment = store.createAction<number>('increment');

store.reducer.connect((state, action, update) => {
  if (action.type === increment.type) {
    update({ foo: state.foo + action.payload });
  }
});

store.dispatch(increment(1)); // state.foo is 1
store.dispatch(increment(1)); // state.foo is 2

store.dispatch(StoreHistory.rollbackAction()) // state.foo is 1
store.getState() // { foo: 1 }
store.dispatch(StoreHistory.rollbackAction()) // state.foo is 0
store.getState() // { foo: 0 }

Package Sidebar

Install

npm i @alcadica/state-manager-history

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

15 kB

Total Files

9

Last publish

Collaborators

  • npm-alcadica
  • octod