Skip to content
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

Adding an ability to see full state from a combined reducer #3664

Closed
airlaser opened this issue Dec 23, 2019 · 1 comment
Closed

Adding an ability to see full state from a combined reducer #3664

airlaser opened this issue Dec 23, 2019 · 1 comment

Comments

@airlaser
Copy link

Do you want to request a feature or report a bug?

Feature

Prior Issues

None

New Features

What is the new or updated feature that you are suggesting?

I would like to see state - the entire, full state, not just the slice - passed as the 3rd argument to a reducer used in combinedReducers.

Why should this feature be included?

combineReducers is wonderful for creating nicely separated, logically consistent reducers. However, there's occasionally edge cases where it is justifiable for one reducer to need data from another. Right now it requires some messy code, either special casing a middleware to attach additional data, arbitrarily getting the store, or awkwardly pulling in extra data to an action when it's created.

With state as a 3rd arg it would be possible to grab the required data easily and cleanly. I think this is actually the biggest downside of it as well, since it could encourage abusing this ability to write reducers that break outside their bounds more often than just edge cases.

It would be fully backwards compatible since no reducer expects a 3rd arg right now.

What docs changes are needed to explain this?

https://redux.js.org/api/combinereducers/ & maybe https://redux.js.org/basics/reducers/ 's section on combineReducers


The core code change for this is just a few characters, I wrote this when I realized I'd have to also update the types & tests but could do a PR for this if it's something that would be considered.

@timdorr
Copy link
Member

timdorr commented Dec 23, 2019

The problem is: which state are you expecting to be passed? The one from before the reducer ran, or passed from other reducers? In the latter case, how do you control ordering? What about circular dependencies?

It's not an easy problem to solve, because the answers to those questions mean different things to different people. We've discussed this quite a bit in #2795, #2750, #1904, #1768, and #1527. It's also related to #1518 and #1400.

The conclusion is there isn't a comprehensive answer that also keeps in line with the central tenants of Redux.

@timdorr timdorr closed this as completed Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants