State: Avoid parameters in memoized selectors getDependants#4939
Merged
State: Avoid parameters in memoized selectors getDependants#4939
Conversation
Contributor
Sounds good, I can't really think of a compelling reason to use it. |
mcsf
approved these changes
Feb 8, 2018
Contributor
mcsf
left a comment
There was a problem hiding this comment.
Looks good, tests well, explanation clear. 🚢 !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request seeks to resolve an issue where memoized selector cache clearing occurs more frequently than anticipated, due to the internal behavior of the underlying rememo library.
Given the following scenario, the cache for
getBlockwould be cleared on every single invocation:This is because memoization compares the result of the dependents between invocations, and in the above case,
blocksByUid[ uid ]will produce different results:https://github.com/aduth/rememo/blob/11644c10d5bb6fa041c387c9ce9e6c26604d3556/es/index.js#L86-L90
As the maintainer of
rememo, unless compelling arguments are made otherwise, I plan to release a subsequent major release dropping support for all but thestateargument ingetDependants(the second argument ofcreateSelector).Testing instructions:
Verify that unit tests pass: