redux-dynamic-config
v0.0.2
Published
Redux store configured to support dynamic registration of reducers and sagas
Downloads
4
Readme
redux-dynamic-config
Redux store configured to support dynamic registration of reducers and sagas
Install
npm install --save redux-dynamic-config
Usage
import React from 'react';
import { Provider } from 'react-redux';
import configureStore from 'redux-dynamic-config';
const name = `Your application name`; // Will be dispatched once initialization is complete!
const state = {}; // Initial store state - defaults to {}
class Root extends Component {
render () {
return (
<Provider store={configureStore(name, state)}>
...
</Provider>
)
}
}
import {registerReducer, registerSagas} from 'redux-dynamic-config';
const MODULE_NAME = 'Module1';
const ACTION_NAME = 'Action1';
const reducer = (state, { type, payload }) => {
switch (type) {
case ACTION_NAME:
// ...
break;
default:
return state;
}
};
registerReducer(MODULE_NAME, reducer);
// sagas
function* saga1 () {
// ...
}
function* listener1({ takeEvery, takeLatest, ...effects }) {
yield takeEvery(ACTION_NAME, saga1);
}
function* listener2() {
// ...
}
registerSagas(listener1, listener2);
Acknowledgments
- Reducer Registry: http://nicolasgallagher.com/redux-modules-and-code-splitting/
License
MIT © ipap360