redux-register-module
Installation
yarn install redux-register-module
See https://www.npmjs.com/package/redux-register-module
Usage
If you try to split your code in different modules who handle their own reducer, own action and own components, you need to add your reducer, your saga handler in the app.
|- src
| - modules
| - my-module1
| - components
| - actions.js
| - reducer.js
| - saga.js
| - ...
| - my-module2
| - components
| - actions.js
| - reducer.js
| - saga.js
| - ...
| - store.js
| - reducers.js
| - ...
This package allows you to register reducer and saga handler from your module. With this, your module stay a standalone package.
Examples
Reducer
Basic implementation for a reducer registered from your module, and injected in your store automatically
node_modules/mymodule/reducer.js
; const initialState = list: ; const reducer = { }; ;
src/reducers.js
; ;; ; // getModuleReducerKey will return the name of where your store module reducers. By default, it will be 'module', you can change it via setModuleReducerKey('myKey')const rootReducer = ;
If you want to read data, you can use the function getModuleState as follow:
; const mapStateToProps = list: list total: total otherModuleList: list;
Of course, if you prefer use reselect, do it:
const myModuleSelector = list;const otherModuleSelector = list; const mySelector = ;
Saga
Basic implementation for a saga registered from your module, and injected in your middleware
node_modules/mymodule/saga.js
; const saga = { ;}; ;
Changelog
1.0.5
- Use native types of redux and redux-saga.
1.0.1 to 1.0.4
- Fix various bug on TypeScript.
1.0.0
- redux-register-module is typed with TypeScript.
getModuleState
is not curried anymore to preserve type, this is a breaking change.