1.0.2 • Published 7 years ago

@alcadica/state-manager-history v1.0.2

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

state-manager-history

branchstatus
masterBuild Status
devBuild Status

npm.io npm.io

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 }