-
-
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
add third argument state to combineReducer. add some documentation #2795
Conversation
Duplicate of #1904, #1768, and #1527. Related to #1518 and #1400. The main arguments against this are:
Those still apply here, so I'm disinclined to allow it as well. If you need to write a more complex reducer, you either need to rethink your reducer/selector architecture or not use something as simplistic as combineReducers. It's not a big function, nor should it be. And I mean that both in terms of code size, but also in terms of scope of use. It should remain very much optional to your use of Redux. I'd almost argue it should be split into a separate package... I'll leave this open so we can discuss things, though. I'm not against being persuaded! 😄 |
@timdorr, hi! Sorry, let me step into this discussion. @gurbraj's way of sharing the state seems pretty forceful (reducer cannot opt to NOT get it) but his intention (!) is nevertheless noteworthy. How about not passing the state (as a third argument) but rather a way to get to it? Options are: a This may be a worthwhile case. I got myself in numerous instances constructing crutches to provide data from two parallel paths. List/data compartments and ids, UI state and errors, forms and UI state. For instance, I have a questionnaire (with sections and questions). I receive answers to it and am interested in looking up a count of questions in a particular section - just to verify correctness of the Now then, you may argue saying 'thunked actions is exactly the place where the logic must reside'. However, I am convinced that programmers' intentions may vary: some would care to have all of their logic reside in actions (say, saga-based), others, would be more inclined to hold it in their reducers, others still - elsewhere. Restricting them on the 'because reasons' pretext is a bit short-sighted, pardon me saying. Back to the lookup function (I take it that how The use of this function can be measured and certain performance bottlenecks identified. (I here recall John Resig's usage measurements of his initial iteration of jQuery, back then..) Still, it must be used first. Bottomline, this may be a pretty unobtrusive way of exposing an entire state to reducers. As to the pattern, a lot of iterator-depending methods' implementations provide, say:
Well, the rule is, the iterated object is 'frozen' till the iteration is over, isn't it so? Thus, it simply resolves to previous finalized state. Did my arguments make any of your strings resonate? |
@AndrewRevinsky, thank you for your comments. I agree with you that the "way of sharing the state seems pretty forceful (reducer cannot opt to NOT get it)". As an alternative solution, what do you think if Regarding using store.getState() in reducers.js: Then store needs to be imported in reducers.js |
This is another way to share state between reducers. Found this way to be more testable than the other ways.
Look forward to your feedback!