Created
February 2, 2017 14:45
-
-
Save pedronauck/7762444741b041cbe4b0d57c5ef18338 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
import { combineReducers } from 'redux'; | |
// Define the context to search files | |
const CONTEXT = require.context('./', true, /\.\/(.*)\/index.js?$/i); | |
// Populate a object with the reducer | |
const importReducer = (req) => (obj, path) => { | |
const [, componentName] = path.match(/\.\/(.*)\/index.js?$/i); | |
const reducer = { | |
[componentName]: req(path).default | |
}; | |
return Object.assign({}, obj, reducer); | |
}; | |
// Generate a object with all reducers | |
const getReducers = (ctx) => | |
ctx.keys().reduce(importReducer(ctx), {}); | |
// Export my root reducer | |
export default combineReducers(getReducers(CONTEXT)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment