Make add/remove refs based on ref parent states and paths instead of contains? check, keep the valid refs after the to-cursor -> adapt cycle#364
Open
verma wants to merge 2 commits intoomcljs:masterfrom
Open
Conversation
…contains? check, keep the valid refs after the to-cursor -> adapt cycle
Author
|
Here is the sample program which helps demonstrate the problem: https://github.com/verma/omfix The timer on top ticks on app-state mutation, the lower timer ticks on local state mutation of a child component. After a while the state mutations to child component start causing the top timer to re-render even though there are no updates to app-state. HTH |
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 is a proposed change for #360
When a value pointed to by ref changes,
update-refsmakes the ref go through a(adapt (to-cursor ...))process. First we keep the "transformed" ref instead of ignoring it.Second, we make the "whether we have a ref" check based on parent state and path into this state instead of a
contains?check (which for collections comes down toidentical?check).Since a newly added ref is never identical to a "transformed" ref, we end up with duplicate refs pointing to the same parent state and path in the component's
__om_refsarray. Since there are always new refs in the__om_refsarray,refs-changed?always tends to returntrueeven when the parent state didn't change, causingshouldComponentUpdateto always return true whenobservepattern is used.After applying this patch, no duplicate refs are added to the
__om_refsarary. The refs stop updating when no parent state changes occur, causing theref-changed?to eventually returnfalseand makingshouldComponentUpdatebehave in an expected manner whenobserveis used.