Skip to content

Instantly share code, notes, and snippets.

@jimbol
Last active February 6, 2017 16:06
Show Gist options
  • Save jimbol/725a1326630f92a09fea843fd1299748 to your computer and use it in GitHub Desktop.
Save jimbol/725a1326630f92a09fea843fd1299748 to your computer and use it in GitHub Desktop.
Partial reducers
// 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