redux-batcher
v0.0.7
Published
allow batched actions
Downloads
26
Readme
redux-batcher
High order reducer that enables batching actions and also plays well with redux-saga :)
Install
$ npm install --save redux-batcher
or
$ yarn add redux-batcher
Usage
import { createStore } from 'redux';
import { batcher, batch } from 'redux-batcher';
const reducer = (state = 0, { type, payload = 1 }) => {
if (type === 'ADD') return state + payload;
if (type === 'SUB') return state - payload;
return state;
};
const store = createStore(batcher(reducer), initialState)
const add5 = { type: 'ADD', payload: 5 };
const sub5 = batch(
{ type: 'SUB' },
{ type: 'SUB' },
{ type: 'SUB' },
{ type: 'SUB' },
{ type: 'SUB' },
);
store.dispatch(add5);
store.dispatch(sub5);
expect(store.getState()).toEqual(0);
redux-saga
if you're using redux saga pass the emitter to the createSagaMiddleware fn
import { emitter } from 'redux-batcher';
createSagaMiddleware({ emitter });