Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for blanket namespace without requiring nested objects #301

Open
Ross-Esmond opened this issue Jun 11, 2018 · 1 comment
Open

Comments

@Ross-Esmond
Copy link

Ross-Esmond commented Jun 11, 2018

I'm using a feature-based model for organizing code. The general idea is that you put Components, Actions, Thunks, Reducers, and Selectors related to one feature in its own folder together.

I'm also using Redux-Actions for a whole bunch of awesome features. The name-spacing, however, tends to break down with this model for two reasons.

  1. Identity Actions can't get namespaces with this method. I have a lot of actions that either have no payload, or the payload is too simple to require a function transform.
  2. Name-spacing an action requires nesting and produces a nested object as a result. My action files are already split by feature; having the actions nested just requires me to perform boilerplate nesting and destructuring to access the feature.

The part of name-spacing that is extremely useful is the fact that the name-space is included in the toString of the action.

What would be helpful is a feature where I could just provide a blanket prefix that applies to all action names behind the scenes:

export const {
  update,
  validate,
  submit
} = createActions(
  {
    UPDATE: {
      ITEM_ONE: () => someResult(),
      ITEM_TWO: () => otherResult(),
      CLEAR: undefined
    }
  },
  'VALIDATE',
  'SUBMIT'
  { prefix: 'MY_FORM' } // <- new api
)

update.itemOne.toString() === 'MY_FORM/UPDATE/ITEM_ONE'
validate.toString() === 'MY_FORM/VALIDATE'

Then I could just use these actions like normal, no destructuring required (unless I set that up like with UPDATE) but the existence of the 'MY_FORM' string on the action names, if used correctly, would prevent MY_FORM/VALIDATE from stepping on other features that have a OTHER/VALIDATE.

I could solve this in userland, but it's not pretty.

@mjetek
Copy link

mjetek commented Sep 3, 2018

Hey @Ross-Esmond
It is not documented yet, but prefix option has been already implemented
#265

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants