Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

@alcadica/state-manager-history

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alcadica/state-manager-history

A history recorder for state-manager

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
2
Created
Source

state-manager-history

branchstatus
masterBuild Status
devBuild 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 }

Keywords

flux

FAQs

Package last updated on 23 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts