-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
suggestion, don't allow store to dispatch action.type of undefined or null #541
Comments
You can define your own middleware that would behave this way. |
Are there any cases where undefined would a valid action type? This
|
I agree it's something we should do by default. This would also effectively force everyone to use "type" instead of bikeshedding on the property name, which is good for the ecosystem. Anybody with use cases for empty type? |
Looking at this semantically, is an action.type of undefined or null even worthy of the term "action"? At its worst being opinionated about falsey actions could discourage some smelly code. |
But what if there is some logic inside the action creator that decides that there is no need to proceed with dispatching (just think about any conditional logic that uses |
But then you need to thunk, whereas a plain action creator can't just On Sun, Aug 16, 2015, 11:37 Johannes Lumpe notifications@github.com wrote:
Wout. |
As @wmertens notes, you can do that just fine with |
Still, I kinda feel like a plain action creator should be allowed to return Obviously, that's trivial middleware, but still… On Mon, Aug 17, 2015, 17:43 Dan Abramov notifications@github.com wrote:
Wout. |
I don't agree. Any real use case I have in mind involves |
D'oh you're absolutely right... On Mon, Aug 17, 2015 at 9:04 PM Dan Abramov notifications@github.com
Wout. |
Done in 3.0.0. |
Is this change compatible with redux-thunk? I'm trying to upgrade https://github.com/frankoid/flux-comparison to redux 3, but when I upgrade from 2.0.0 to 3.0.2 then I start seeing an |
It's compatible. We're actually doing a good thing in 3.0: this line uses a constant that was never defined. |
@frankoid By the way, if you don't mind, I'd like taking a stab at updating it myself. There are a few things I'd change there.. |
@gaearon thanks! I've got it working now. Happy for you to update it yourself - I am learning React and Redux and was using the upgrade as a learning exercise, so I'm not up to speed with Redux best practices. |
@frankoid FYI, I updated it in the flux-comparison repo. |
why is type: null allowed as a valid action ? isn't it better to check for both null and undefined ? Are there any use cases where null is a valid action type ? maybe 0 is valid but don't think null is |
I've haven't given this a lot of deep though so I'll probably someday want this post erased from the internet, but a few times already I've screwed up my 'constants',
You can see in the below example, if I misspell ACCRUE either here or in the constants file (I'm not even sure if its spelled correctly here), it becomes undefined and then the reducer happily uses the default switch, and because store.dispatch is inclined to put whatever it pleases (@@init/etc) through the default path, I can't use that to catch screw ups. Why not throw an exception when a falsey action.type is dispatched, since its so easy to do and sometimes difficult to catch, even in tests.
The text was updated successfully, but these errors were encountered: