Extracts the reducer blueprint for a model to src/reducers

extract reducer

CLI command to extract one or more of the reducers generated by the framework into your project. This will allow you to see the code that gets executed, and change it if needed.


To use this command, you need to specify the name of the model you'd like to extract a reducer for, as well as the name of the reducer you'd like to extract.

lore extract reducer [model]/[reducer]

For example, to extract the find reducer for the post model, you would run the command lore extract reducer post/find.

If you do NOT specify a reducer, the command will extract ALL reducers for that model. For example, this command:

lore extract action reducer

Will extract all reducers for the post model, and create the files below:


The index.js file is the actual reducer, that consumes the other files as child reducers. The index.js file looks like this:

import { ActionTypes } from 'lore-utils';
import byId from './byId';
import byCid from './byCid';
import find from './find';

const initialState = {
  byId: undefined,
  byCid: undefined,
  find: undefined

export default function(state, action) {
  let nextState = state || initialState;

  // If we receive an action to reset the store (such as when logging out)
  // reset the state to the initial state
  if (action.type === ActionTypes.RESET_STORE) {
    nextState = initialState;

  const _byId = byId(nextState.byId, action);
  const _byCid = byCid(nextState.byCid, action);
  const _find = find(nextState.find, action, {
    nextState: {
      byCid: _byCid,
      byId: _byId

  return {
    byId: _byId,
    byCid: _byCid,
    find: _find