Reducers

Data-caching tier for Lore

Concept

Reducers are responsible for storing and updating application state. They receive actions dispatched from the action creators, and based on the ActionType, update the piece of Store state they're responsible for.

You can learn more about reducers in the official Redux documentation.

When you create a model in Lore, the framework automatically creates a set of reducers for storing resources individually (the byId and byCid reducers) as well as the find reducer which caches server responses based on query and pagination information.

The blueprints have an implicit file structure that looks like this:

|-src
  |-models
    |-post.js
  |-reducers
    |-post
      |-byCid.js
      |-byId.js
      |-find.js

All blueprints reducers can be overridden by creating a file that matches the location of the blueprint. For example, if you wanted to override the find blueprint for a post model, you would create your own reducer at reducers/post/find.js.

|-src
  |-models
    |-post.js
  |-reducers
    |-post
      |-find.js

Extracting the Existing Reducers

If you're ever curious what the blueprints for Lore look like, or need a quick way to modify a specific reducer's behavior, Lore provides a CLI command that will provide a model-specific copy of the blueprints for you to debug and/or modify.

To extract the reducers for the post model in our example above, run this command:

lore extract reducer post

You can learn more about the extract command in the CLI documentation.