3 ms·
> Say, if you keep you containers, reducers, and actions in their own directory trees. That layout is the biggest reason it took me so long to understand it wh
by Izkata 9y ago
> Say, if you keep you containers, reducers, and actions in their own directory trees.
That layout is the biggest reason it took me so long to understand it when my team brought it in.
It goes a bit against the spirit of Redux, but the tutorials really should pair up action and reducer in the same directory, then later explain why the other way is also useful.
We currently do this:
state/
|---some_piece_of_state/
| |------reducer.js
| |------actions.js
| |------tests.js
|
|---another_piece_of_state/
|------reducer.js
|------actions.js
|------tests.js
It ended up way, way easier to understand and get people in on it, because in the vast majority of cases we don't need multiple reducers listening to the same action.
- acemarke 9y agoRedux itself doesn't actually care how you organize your file structure (per the FAQ entry at https://redux.js.org/faq/code-structure https://redux.js.org/faq/code-structure ). For the size of the tutorials, it's probably simpler to use a "folder-by-type" structure. But yes, for real apps, I myself have settled on a "folder-by-feature" structure. Note that either approach is completely orthogonal to whether you have multiple reducers listening to the same action. The tutorial is already trying to explain a lot of concepts that are new to most people, so we try to keep it focused on the meaningful concepts. Throwing in side discussions on folder structures would probably add more confusion at that point in the learning curve.
- Izkata 9y agoSee, the part we disagree with seems to be here: > so we try to keep it focused on the meaningful concepts. For me, scattering a single feature across multiple directories makes it far harder to understand what relates to what. It's _less_ meaningful to group by type than by feature, which makes it harder to learn than it should be. I'm not saying the docs should go into asides about the alternative structures all over, but rather the people promoting Redux should definitely consider whether or not their examples smell more of spaghetti code than they need to be.
- acemarke 9y agoI don't currently have time to go revamp the docs and examples myself, but if you'd like to file a PR to rework things, we can definitely take a look at it.
- jwdunne 9y agoI agree. When you learn React, small examples typically follow folder-by-type but, in larger apps, it becomes apparent this doesn't work. If you take the recommended path, i.e add redux iff you need it, you've already settled away from folder-by-type. It's natural to organise by feature since you're generally doing it anyway by that point. Instead of a rework, it might be easier to add a small page on folder structure. Noticed you on Reactiflux too, hi!