-
-
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
"Refactoring Reducers" recipe shouldn't promote over-abstraction #3173
Comments
/me raises hand Apparently I'm the guilty one here :) The train of thought was to illustrate that:
In fairness, I did write this at the top of the page:
|
For what it’s worth, I prefer the final result of that recipe to the starting example. I work on a very complex app that manages its state with redux, and our general pattern is to use an immutable.js-compatible I do, however, think that the “Extracting Utility Functions” isn’t particularly helpful and distracts from the goal of teaching common reducer patterns. It doesn’t help that it’s the very first step in the article. So I would say that removing that extra abstraction and verbiage could help avoid making everything look more complicated than it is. And I personally would also remove the “Reducing Boilerplate” section, though I also get the justification for keeping it. A few thoughts: it comes before introducing |
@gaearon Designing software is a very subjective topic, and libraries should stay as neutral as possible. There are people who like such approach "split logic to many tiny functions", but other people don't like it because it's better to read the real code instead of function names. See for example Jest. There are many books which describe best practices for testing, but you won't find any "receipts" in Jest. They just give you a tool and you can do whatever you want. The same should apply to Redux. Redux docs are going definitely in the wrong direction. Documentation tries to describe literally everything: "integration with X library", "N ways to do Y", design problems etc. Also, there are tons of information that 99.999% users won't need like "Monkeypatching Dispatch". Developers who started using redux 2-3 years ago probably don't need to check docs anymore, because they already have their own setup. New developers probably will have this problem. |
Very much this. I was reading that section today and found it very surprising that it was part of the tutorials. As a user I don't need to know how the dispatcher / middleware are implemented internally; I just need to know how to use them. |
@pdfrod : agreed. When we revamp the docs (soon, hopefully), I want to have one page that talks about how and why to use middleware in general, and another page that talks specifically about why middleware are implemented using that pattern. |
From https://redux.js.org/recipes/structuringreducers/refactoringreducersexample:
I'd argue the original code is clearest of all examples, and every next iteration makes it more complex due to giving names to every intermediate concept that doesn't really deserve a name. That's how people come to thinking Redux is complex.
I understand where the writer is coming from. But I don't think code like this should look like a recommendation. Maybe a less extreme version of this could be helpful but I think this form is giving the wrong impression.
The text was updated successfully, but these errors were encountered: