@alcadica/state-manager-history
v1.0.2
Published
A history recorder for state-manager
Downloads
16
Readme
state-manager-history
| branch | status | |--------|--------| | master | | | dev | |
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 }