-
-
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
REPLACE action for replaceReducers #2673
Conversation
761b399
to
ee1b0aa
Compare
527989f
to
fd3d79b
Compare
Hey that test looks familiar. 😉 Glad you liked it. |
@timdorr what if the nextReducer depends on the INIT action for proper behavior? Or is it just understood that a reducer must not depend on the INIT action? |
Yes, thank you! I'll amend the commit so you get credit.
It's the latter. INIT is a "private" action that shouldn't be relied on outside of the Redux package. We're looking at making it both randomized and more private in 4.0. |
Gotcha. I also just saw Dan's advice in #186. Should have done a quick google first. |
fd3d79b
to
eea98f5
Compare
eea98f5
to
3569724
Compare
As requested in #1736 (comment), this also adds a randomized name to the private actions, making them harder to look for. |
INIT: '@@redux/INIT' | ||
const ActionTypes = { | ||
INIT: '@@redux/INIT' + Math.random().toString(36).substring(7).split('').join('.'), | ||
REPLACE: '@@redux/REPLACE' + Math.random().toString(36).substring(7).split('').join('.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it makes sense to have this random token generator in a function ? (since it being used at least twice here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, if we start having more than just two. I'm find with the duplication for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need two separate random strings generated? Seems that you can generate it once and use in both action types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but that seems like splitting hairs. It doesn't really matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, fair enough. There's also https://github.com/reactjs/redux/blob/master/src/combineReducers.js#L72. Does it make any sense to put all of them in the same place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm with @timdorr here. When applying the D.R.Y. principle, it is critical to distinguish between essential duplication and coincidental duplication, because trying to "DRY-up" the latter kind can increase code complexity. In cases where it is not clear what kind of duplication it is, one best practice is to permit the duplication until it causes actual pain. This seems to be what @timdorr is doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Quinned : highly relevant here: https://twitter.com/acemarke/status/901329101088215044 :) Also, https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstraction .
3569724
to
e54a7f2
Compare
Without further objections, I think this is OK to merge in. If anyone has any issues with it, feel free to revert or submit a PR with improvements. |
* Add an explicit private action type for replacing reducers * Make this a const while we're at it... * Triple equals for lint * Add a random string to the "private" actions.
* Add an explicit private action type for replacing reducers * Make this a const while we're at it... * Triple equals for lint * Add a random string to the "private" actions.
* Add an explicit private action type for replacing reducers * Make this a const while we're at it... * Triple equals for lint * Add a random string to the "private" actions.
Fixes #1636
Provides a separate private action for when we replace reducers. This allows us to specifically handle this case, which resolves a false dev-only warning for combineReducers currently.