0.0.7 • Published 7 years ago

redux-batcher v0.0.7

Weekly downloads
20
License
MIT
Repository
github
Last release
7 years ago

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

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago