Model Docs
createModel
Creates a redux-mvc model: getters, setters and actionCreators
createModel(definition: ModelDefinition)
Parameters
definition
ModelDefinitionInterface: {namespace: String,iniState?: Object,reducers?: Map<ReducerFunction>,singleton?: Boolean,}
namespace: String
The namespace of the model.
iniState?: Object
Defines the initial state of the namespace. It will act as default if an instance is not found. Also redux-mvc will create a getter and setter for each key in the iniState object.
Default:
false
.reducers?: Map<ReducerFunction>
Defines the reducers with the following signature of the model.
ReducerFunction: (state: Object, action: ActionPayload) -> Partial<state>redux-mvc will shallow merge the returned partial state to the previous state. redux-mvc will create one ActionCreator for each key in the reducers Map.
Default:
{}
.singleton?: Boolean
Defines if the model is a singleton, one per each context. Meaning that every action goes to the default instance, and every getter returns the state of the default instance.
Default:
false
Return value
model
Model: {namespace: String,iniState: Object,reducers: Map<ReducerFunction>,singleton: Boolean,actions: Map<ActionCreator>,getters: Map<Getter>,}
getter
Returns key property from the state
Getter<key>: (state: Object, props?: Object) -> Pick<state, key>
Parameters
state: Object
The module’s state Object.
props?: Object
The only prop that getters use is props.instanceId to return the key from the specified instanceId.
If the instanceId is not found, the getter will return the DEFAULT_INSTANCE_ID slice.
Default:
{}
Special getters
redux-mvc will provide 3 special getters in case you need them:
getters.instance
Will return the entire instance object specified by the instanceId as props.
getters.namespace
Will return the entire namespace object.
getters.module
Same as the identity function, it will return the entire module state.
actionCreator
Creates an ActionPayload out of payload, props and error
ActionCreator: (payload?: Any, props?: Object, error?: Any) -> ActionPayload
Parameters
payload?: Any
Any information that should be communicated through the action
Default:
undefined
props?: Object
Additional info that should be sent in the ActionPayload. E.g.: meta, optimist…
Note: meta.instanceId is used by redux-mvc to specify the target instance of the action.
Default:
{}
error?: Boolean
Specify if there was an error or not.
Default:
false
Return value
- actionActionPayload: {payload: Any,...props,error: Boolean}