Decorators
addReducer
- Creates a reducer from all the module dependencies.
- Merges the iniState from all the module dependencies.
- Merges the reducer functions from all the module dependencies.
Usage
Should be executed after merging all the modules:
const newModule = R.compose(...addReducer(),...merge(counter),merge(searchBar))(module)
Return value
newModule
newModule = {...module,iniState: Object,reduers: Map<ReducerFunction>,reducer(state, action) {...},}
Methods:
reducer
reducer: (previousState: Object, action: ActionPayload) -> nextState: ObjectComputes the nextState out of the previousState and action
addLifecycle
Adds lifecycle constructor and componentWillUnmount methods to the module for store creation. This methods will be called by the redux-mvc Context provider.
Usage
Should be executed after all the other decorators.
const newModule = R.compose(addLifecycle(),...merge(counter))(module)
Return value
newModule
newModule = {...module,constructor() {...},componentWillUnmount() {...}}
Methods:
constructor:
constructor: ({ moduleInstances, contextId, persist }) -> moduleInstance: ModuleInstanceCreates the store and returns the moduleInstance.
Parameters:
moduleInstances: Map<ModuleInstance>
All the instances of modules keep by the Context provider.
contextId: Symbol | String
The id of the context.
persist: Boolean
Indicates to persist the store object after the Context is unmounted.
Return Value
Should return the moduleInstance object with the store in it.
moduleInstance = {store: StoreObject}
componentWillUnmount
componentWillUnmount: ({ moduleInstances, contextId, persist }) -> moduleInstance: ModuleInstanceRemoves the store from the moduleInstance if persist is false.
Parameters
moduleInstances: Map<ModuleInstance>
All the instances of modules keep by the Context provider.
contextId: Symbol | String
The id of the context.
persist: Boolean
Indicates to persist the store object after the Context is unmounted.
Return Value
It may return the moduleInstance object with the store in it.
moduleInstance = {store?: StoreObject}
addBridge
Adds the trackGlobalNamespaces array and the dispatchToGlobal filter function, that will later be used by the bridgeMiddleware.
Usage
Should be executed after any merge decorator if you want to override the default trackGlobalNamespaces and dispatchToGlobal.
const newModule = R.compose(addBridge({ trackGlobalNamespaces, dispatchToGlobal })...merge(searchBar),)(module)
Parameters
trackGlobalNamespaces?: Array<String>
The array of namespace dependencies from the global context.
If trackGlobalNamespaces is not passed, then addBridge will merge the trackGlobalNamespaces from all the module dependencies.
dispatchToGlobal?: (action: ActionPayload) -> Boolean
This predicate function will be used by the bridgeMiddleware to forward actions to the global context.
If dispatchToGlobal is not passed, then addBridge will dispatch to the global context any action that is not in any namespace of the module dependencies.
Return value
newModule
newModule = {...module,trackGlobalNamespaces,dispatchToGlobal,}
createModule
Helper.
Applies addReducer and addLifecycle in that order to create a module.
Usage
Can be executed by itself,
const newModule = creatModule(model)or after any other decorator.
const newModule = R.compose(creatModule,...addBridge(...),merge(searchBar),merge(counter))(model)
Parameters
model: ModelInterface
Return value
newModule
newModule = {...model,reducer(state, action) {...},constructor() {}, // creates the store objectcomponentWillUnmount() {} // creates the store object}