Skip to content

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 with meta.entities property;
  • normalizes the action payload property based on the value of meta.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 on store/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

Clone this wiki locally