-
Notifications
You must be signed in to change notification settings - Fork 4
Reducers and action creators aren't a one-to-one mapping #8
Comments
Or maybe provide it as a simple helper for reducers and actions that are really coupled, still adding a warning about it of course. |
As soon as you have such helper used in a codebase new people start to structure their code in similar ways because they think that's how it should be done. The point of Flux and Redux is to make it easy to suddenly start reacting to the same action in a different place. You don't know which actions you'll need to handle in different places in advance. One needs to look at the code not just from "how it looks now" perspective but also "how will it evolve" and "how can we reduce risks when requirements change". This pattern locks you into a very particular way of doing things. When you'll get more requirements you'll have to rewrite the part that used this helper anyway. This is why I consider providing such helper harmful, even if it seems to make code simpler in some cases. Requirements change! |
Hi, @gaearon :) You're correct. I have tried to make redux modules (what called by ducks in here.) look good. To me, redux modules in there, so verbose and has too many repeats of action names. I want to make it short and simpler. But I missed a point of relations between action creator and reducer. I have added some warning messages to README.md. And also, I'll try to fix functions for fit with basic concepts for Flux and Redux. Thanks again @gaearon. |
Have added warning messages and refactor functions for support M:N relationship. |
I'm building a chat app, but the data on the server has only messages list. |
look great, but need to connect more than one reducer to the action. I agree that this approach tide together action and reducer. |
This part of README worries me a lot:
It reinforces a very common misconception about Redux: namely that action creators and reducers are one-to-one mapping.
This is only true in trivial examples, but it is extremely limiting in real applications. Beginners exposed to this pattern couple reducers and action creators, and fail to realize they're meant to be many-to-many and decoupled.
Many reducers may handle one action. One reducer may handle many actions. Putting them together negates many benefits of how Flux and Redux application scale. This leads to code bloat and unnecessary coupling. You lose the flexibility of reacting to the same action from different places, and your action creators start to act like “setters”, coupled to a specific state shape, thus coupling the components to it as well.
I suggest you to refrain recommending this approach, or at least add a warning that Redux doesn't endorse it.
The text was updated successfully, but these errors were encountered: