Last active
February 6, 2017 16:06
-
-
Save jimbol/725a1326630f92a09fea843fd1299748 to your computer and use it in GitHub Desktop.
Partial reducers
This file contains hidden or 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
// my-reducer.js | |
function myReducer(plugins, state, action) { | |
// ... | |
} | |
// reducers.js | |
import { myReducer } from './my-reducer'; | |
export const reducers = { | |
myReducers, | |
}; | |
registerReducers(reducers); | |
// | |
// plugins/register-reducer.js | |
// | |
import { partial } from 'lodash'; | |
let reducers; | |
export function registerReducer(rawReducers) { | |
reducers = rawReducers; | |
} | |
export function setUpReducers({ constants, actionCreators }) { | |
const reducerPartials = {}; | |
Object.keys(reducers).forEach((key) => { | |
reducerPartials[key] = partial({ constants, actionCreators }); | |
}); | |
return combineReducers(reducerPartials); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment