-
Notifications
You must be signed in to change notification settings - Fork 293
Example redux modules
Diego Haz edited this page May 19, 2017
·
24 revisions
There're a bunch of redux modules
already on the example app
. Here's an explanation of each of them.
The entities
module handles normalization through the normalizr library. The middleware does 3 things:
- intercepts
actions
dispatched withmeta.entities
property; - normalizes the action
payload
property based on the value ofmeta.entities
; - dispatches an
ENTITIES_RECEIVE
action with normalized entities, which will be handled by the entities reducer.
To be able to have an entity normalized, you need to do 3 things:
-
add
meta.entities
to the success action:const resourceCreateSuccess = detail => ({ type: RESOURCE_CREATE_SUCCESS, payload: detail, + meta: { + entities: 'resource', + }, })
-
create
resource
schema onstore/entities/schemas.js
export const resource = new schema.Entity('resource')
-
on containers, use
selectors
from the entities store instead of the resource one:- import { fromResource } from 'store/selectors' + import { fromResource, fromEntities } from 'store/selectors' ... const mapStateToProps = state => ({ - list: fromResource.getList(state), + list: fromEntities.getList(state, 'resource', fromResource.getList(state)), })
TODO
TODO
TODO
TODO
TODO
Special thanks to @kybarg and @protoEvangelion for helping to write this Wiki. Please, feel free to edit/create pages if you think it might be useful (also, see #33)