Data: Avoid calling listeners on unchanging state #5339
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related: #5334
This pull request seeks to optimize the behavior of
subscribe
to avoid calling a listener except in the case that state has in-fact changed. This is a departure from Redux wheresubscribe
is called on every dispatch, whether or not it results in a changed state. It's a departure I'd argue is warranted: listener callbacks don't and shouldn't have access to the dispatched action. That they are expected only to read from state implies that a subscriber react to a change, so an expectation better reflected in these changes.Further, it would be difficult to introduce the desired optimization mentioned in #5334 to avoid running
mapSelectToProps
ofwithSelect
without this change, as we don't know which store the mapping function will select from and to implement would require a shallow equality test on all stores (in some cases more wasteful than to just allow the mapping to be performed).Testing instructions:
Verify unit tests pass: