Methods
combineReducers()
Wrapper around vanilla combineReducers()
from redux
package.
Adds support for Controller class instances in place of regular reducer
functions. Each instance encountered is replaced with the result of
Controller.reducer()
call. The instance is then saved under controllers
key of the returned function. controllers is passed up the chain and
is intended to be used by the createStore()
.
- Source:
Container(WrappedComponent, …mappings)
Connects a React component to a Redux store. Additionally to regular connect()
method
Container supports an extensive mapping functionality designed to work nice with
Controllers.
Container is capable of mapping any part of a Redux state tree to the props of the wrapped component. When mapping parts of the tree managed by controllers, Container calls Controller.$ method to select the data, thus calling any selector methods defined on the Controller level.
If mapping the path exactly equal to Controller.mountPathString, dispatch functions are also mapped by default.
The list of mapping options:
Mapping | Description | Result |
---|---|---|
"path.*" |
Map all sub-keys at path to props . |
path.key1 to props.key1 path.key2 to props.key2 ... |
{ "path": "*" } |
Same as "path.*" |
|
"path.key" |
Map the path to the prop that equal to the last key in the path. | path.key to props.key |
{ "path.key": "remapKey" } |
Map the path to the prop that is explicitly specified. | path.key to props.remapKey |
"path.dispatch*" |
Only map dispatch functions of the controller to props. | path.dispatchFunc1 to props.func1 path.dispatchFunc2 to props.func2 ... |
{ "path.dispatch*": "*" } |
Same as "path.dispatch*" |
|
{ "path.dispatch*": "funcs"} |
Map all dispatch functions of the controller to the specified prop. | path.dispatchFunc1 to props.funcs.func1 auth.dispatchFunc2 to props.funcs.func2 ... |
"path.select*" |
Only map state managed by the controller to props (no dispatches). | |
"path.$" |
Same as "path.select*" |
|
{ "path.select*": "*" } |
Same as "path.select*" |
|
{ "path.select*": "keys" } |
Only map state managed by the controller to props (no dispatches). | path.key1 to props.keys.key1 path.key2 to props.keys.key2 ... |
{ "path": (nextProps, value) => { ... } } |
Provide custom AssignerFunction to map value to the nextProps . nextProps object should be modified in place. Function is not expected to return anything. |
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
WrappedComponent |
React.Component
|
Component to connect. |
|
mappings |
string
|
Object.<string, (string|AssignerFunction)>
|
<repeatable> |
Any amount of mappings that should be applied when connecting Redux store to the component. |
createStore()
Wrapper around vanilla createStore()
from redux
package. Creates the
regular Redux store and extends it with getController()
function.
- Source:
Type Definitions
AssignerFunction(nextProps, value)
Can be used in Container to add adjustment to default remapping logic.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
nextProps |
Dictionary of properties that wrapped component is about to get. This object should be modified in place. It doesn't include value |
|
value |
Value obtained from the specific mapping. |
Example
Container(MyComponent, {
'books': (nextProps, books) => {
nextProps.book = foo.books[nextProps.bookId]
// Nothing else from books will be mapped
// MyComponent will receive both book and bookId in props
}
})