0.0.2 • Published 6 years ago

redux-dynamic-config v0.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

redux-dynamic-config

Redux store configured to support dynamic registration of reducers and sagas

NPM Build Status

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

License

MIT © ipap360