modular-redux-thunk icon indicating copy to clipboard operation
modular-redux-thunk copied to clipboard

Suggestion: `selector` as string sugar

Open dallonf opened this issue 9 years ago • 0 comments

I've noticed a very common pattern when writing single-value modules:

const someValue = {
  reducer: (state = null, action) => {
    switch (action.type) {
      case SOME_ACTION:
        return action.payload
      default:
        return state;
    }
  },
  // Note the identity selector here
  selectors: { getOrgsTotalCount: (state) => state },
  actions: { someAction: /*...*/},
};

It might be slightly convenient to instead write this property as:

const someValue = {
  reducer: /* same as before */,
  // Note the identity selector here
  selector: 'getOrgsTotalCount',
  actions:  /* same as before */,
};

dallonf avatar Sep 15 '16 15:09 dallonf