redux-batcher

0.0.7 • Public • Published

redux-batcher

Codeship Status codecov

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 });

Readme

Keywords

none

Package Sidebar

Install

npm i redux-batcher

Weekly Downloads

11

Version

0.0.7

License

MIT

Last publish

Collaborators

  • tugorez