New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@alcadica/state-manager-transactions

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-transactions

Transactions for state-manager

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
2
Created
Source

@alcadica/state-manager-transactions

Coverage Maintainability

This plugin enables transactional state management

Install

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

Usage

import createStore from '@alcadica/state-manager';
import Transactions from '@alcadica/state-manager-transactions';

const store = createStore({
  test: 0,
});

store.use(Transactions());

const increment = createStore.createAction('increment');

store.reducer.connect((state, action, update) => {
  update({
    test: state.test + (typeof action.payload === 'number' ? action.payload : 1),
  });
});

store.dispatch(Transactions.begin());
store.dispatch(increment()); // state.test is '1'
store.dispatch(increment()); // state.test is '2'
store.dispatch(increment()); // state.test is '3'
store.dispatch(increment(7)); // state.test is '10'
store.dispatch(Transactions.undo());

console.log(store.getState().test) // outputs 0, we cancelled the transaction

store.dispatch(Transactions.begin());
store.dispatch(increment()); // state.test is '1'
store.dispatch(increment()); // state.test is '2'
store.dispatch(increment()); // state.test is '3'
store.dispatch(increment(7)); // state.test is '10'
store.dispatch(Transactions.end());

console.log(store.getState().test) // outputs 10, we ended the transaction

Licence

MIT

Keywords

flux

FAQs

Package last updated on 23 Jan 2019

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