Created
October 9, 2016 18:56
-
-
Save farism/3bb62482f72b617b13b7940706de98ed to your computer and use it in GitHub Desktop.
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
import { combineReducers, createStore } from 'redux'; | |
import { local } from 'redux-fractal'; | |
import R from 'ramda'; | |
const combineModules = modules => { | |
return modules.reduce((acc, module) => ({ | |
reducers: { ...acc.reducers, [module.name]: module.reducer }, | |
actions: { ...acc.actions, ...module.actions }, | |
}), { actions: {}, reducers: {} }); | |
}; | |
export default R.curry(config => { | |
if (!config.modules || config.modules.length === 0) { | |
return local(config); | |
} | |
const { actions, reducers } = combineModules(config.modules); | |
return local({ | |
createStore: () => createStore(combineReducers(reducers)), | |
mapDispatchToProps: dispatch => { | |
return R.map(fn => payload => dispatch(fn(payload)), actions); | |
}, | |
...config, | |
}); | |
}); | |
// usage | |
localWithModules({ | |
key: (props) => "keyname" | |
modules: [ModuleA, ModuleB], | |
})(Component) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment