Skip to content

Instantly share code, notes, and snippets.

@dralletje
Created October 20, 2015 14:22
Show Gist options
  • Save dralletje/7f0296d11c9eb5b13ceb to your computer and use it in GitHub Desktop.
Save dralletje/7f0296d11c9eb5b13ceb to your computer and use it in GitHub Desktop.
function batchActions(...actions) {
return {
type: 'BATCH_ACTIONS',
actions: actions
};
}
// usage
store.dispatch(
batchActions(
doSomething(),
doSomethingElse()
)
);
function enableBatching(reducer) {
return function batchingReducer(state, action) {
switch (action.type) {
case 'BATCH_ACTIONS':
return action.actions.reduce(reducer, state);
default:
return reducer(action, state);
}
}
}
// usage
let store = createStore(enableBatching(reducer));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment