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

Why must an action "NOT include properties other than type, payload, and error, and meta"? #40

Open
faceyspacey opened this issue Nov 3, 2016 · 4 comments
Labels

Comments

@faceyspacey
Copy link

faceyspacey commented Nov 3, 2016

I for example have built a history management package that changes URLs based on action types and a routing config map. Using middleware, I add location and prevLocation keys to payloads, but I rather pass them as keys on the action, so that the payload would be what it was before adding my middleware. So would it really be a crime for a package to add additional keys?

ps. I could add my keys to meta, but I feel like too many other packages are possibly hijacking that, and could break what I've put on the meta key. That basically summarizes the benefits of allowing for additional keys--package authors can essentially namespace their "meta" data and therefore do a better job of preventing it from being fooled with. Perhaps it's just best application developers stick to these conventions so that they can take advantage of the larger number of supporting packages that conform to the FSA standard, but package developers can make the choice to opt out of such benefits if they choose.

@aCandidMind
Copy link

You could easily namespace inside the meta object. Putting your namespace top-level only saves you from some code blatantly clearing meta. Don't know why someone would do that. Which brings me to the question of why actions aren't immutable? To me they should include all information when they are created. It's not like they go through middleware chain or is that me being to inexperienced with Redux?

@faceyspacey
Copy link
Author

faceyspacey commented Nov 8, 2016

they do go through the middleware chain. Each middleware can modify the object. The object isn't a a string or a number, so unless we're using the Immutable library, can totally be mutating. But that doesn't really matter because each middleware can return an entirely different object as well, but after having done whatever they want to "it," including assigning to the key and perhaps overwriting what you assigned to it. In fact, that's what some middleware do--tack on meta data to your actions object and probably many other things. So my concern is someone doing that incorrectly (by simply assigning to action.meta rather than incorporating its current values) and erasing my meta data.

@unional
Copy link
Contributor

unional commented Dec 18, 2016

The reducer being a Pure function, it should not really make changes to the action either. I agree with @aCandidMind middleware should not change action.

The object isn't a a string or a number, so unless we're using the Immutable library, can totally be mutating.

The user is not necessary using an immutable library for state either, but the reducer should not change the state anyway.

UPDATE: It's not really possible to do. e.g. thunk is dispatching a function to begin with. So middleware can change action, as long as the final action sending to reducer is serializable.

@peterjacobson
Copy link

Lack of other action props is preventing me integrating this awesome module with redux-optimist, which seems to expect optimist and response properties in the action object. I could be wrong here, still trying to fully understand what's going on

Would you consider allow other action prop types if only to interface with other excellent modules?

@JaKXz JaKXz added the question label Sep 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants