Created
October 20, 2015 14:22
-
-
Save dralletje/7f0296d11c9eb5b13ceb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function batchActions(...actions) { | |
return { | |
type: 'BATCH_ACTIONS', | |
actions: actions | |
}; | |
} | |
// usage | |
store.dispatch( | |
batchActions( | |
doSomething(), | |
doSomethingElse() | |
) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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