Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 1.01 KB

README.md

File metadata and controls

41 lines (30 loc) · 1.01 KB

Redux Action Batcher

Build Status

Reducer, middleware and action creator that enables to batch own as well as custom middleware actions such as redux-react-router push actions.

Getting started

import {createStore, applyMiddleware} from 'redux';
import {batchActions, batchingMiddleware, enableBatching} from 'redux-action-batcher';
import {routerMiddleware, push} from 'react-router-redux';

const USER_DATA_RECEIVED = 'USER_DATA_RECEIVED';

const reducer = (state, action) => {
  switch(action.type) {
    case USER_DATA_RECEIVED:
      return {...state, name: action.payload.name}
    default:
      return state;
  }
};

const store = createStore(
  enableBatching(reducer),
  applyMiddleware(
    batchingMiddleware,
    routerMiddleware(browserHistory)
  )
);


store.dispatch(batchActions(
  {type: USER_DATA_RECEIVED, name: 'John Snow'},
  push('/profile')
));