-
-
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
Subscribing to only parts of store #2060
Comments
A redux store has just one reducer function that returns the next state given the current state and an action. The "parts" of that state you're talking about are an implementation detail, likely introduced to your mind by the What you might want to do is to "connect" to a set of separate stores, each with its own reducer, See the lengthy discussion here for details and tradeoffs: #1385 |
This is a frequently asked-for feature. The answer is that Redux deliberately provides low-level primitives such as For Please see the relevant question in the FAQ: http://redux.js.org/docs/faq/StoreSetup.html#store-setup-subscriptions . |
@markerikson |
Some part of the code would still be running checks to see whether the relevant slice of state changed. Really, the only question is whether that check is happening inside of There are some addons built by the community that add more specific diffing logic on top of the core It's also important to understand the distinction between "reducers" and the state as a whole. As the Structuring Reducers docs point out, you really only have one reducer function: the root reducer that you passed to |
That makes sense, thank you for the explanation! |
Connect compares the entire store to the previous version of the store every time it receives an action. Is there a reason why there's no customization to listen to particular parts of the reducer? The advantage is that a whole lot of mapStateToProps could be saved from running in a large app.
For example if the reducer shape is
{A: {a1: '1', a2: '2'}, B: ...}
and I have a component CompA who's mapStateToProps returns a2 value, and B has frequent updates (say for example, updating on scroll position), then CompA's mapStateToProps would also execute on every update. I feel like there's benefits to allowing a comparison in connect to see if A has changed and only call mapStateToProps if it did, especially if we use immutable data structures and a simple equality would work.
The text was updated successfully, but these errors were encountered: