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

fix for references to objects being broken after replacing the node #1053

Merged
merged 16 commits into from
Oct 23, 2018

Conversation

xaviergonz
Copy link
Contributor

Fixes #1052

@Amareis
Copy link

Amareis commented Oct 21, 2018

Does you completely disable optimization with "object" mode in StoredReference?

@xaviergonz
Copy link
Contributor Author

xaviergonz commented Oct 21, 2018

it wasn't much of an optimization given there is an identifier cache underneath that keeps a hash map with a pointer to the node.
The optimization is what introduces a way to skip the identifier cache, so when the cache gets out of sync with the actual node it points to it breaks.

@xaviergonz
Copy link
Contributor Author

Also, at first I tried to keep it, but apparently making a mutation (in this case of the ref object) in the middle of a read operation (getValue) makes the system go nuts

@xaviergonz
Copy link
Contributor Author

Ok, I added back resolve optimizations, but in a better way since now it even works for refs that use ids, not only for refs that use objects
This way resolution of references will only be done once (unless a new object with a same id comes in / dies, then it needs to be re-resolved)

@xaviergonz xaviergonz self-assigned this Oct 21, 2018
@xaviergonz xaviergonz added bug Confirmed bug enhancement Possible enhancement labels Oct 21, 2018
@xaviergonz xaviergonz added the require('@mweststrate') @mweststrate input is required! label Oct 22, 2018
Copy link
Member

@k-g-a k-g-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I planned to tailor some time for mutable identifiers proposal and stumbled upon this issue/PR. Thanks for great work :) I am going to wait until this one is released before proceeding with mutable identifiers.

this.targetType.name
}' (from node: ${node.path})`
)
this.resolvedNode = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call it resolvedReference or just resolved, becuase this.resolvedNode!.node later on looks quite strange :)

lastCacheModification: string
}

constructor(mode: "identifier" | "object", value: any, private readonly targetType: IAnyType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have missed something, but it seems like we do not need mode at all for now. In constructor we can do if (isStateTreeNode(value)) instead of mode === "object" (becuase mode is chosen by that criteria at instantinate).
During reconcilation we could do:

  const compareByValue= isStateTreeNode(newValue)
  const ref = current.storedValue as StoredReference
  if (!compareByValue && ref.identifier === newValue) return current
  else if (compareByValue && ref.resolvedValue === newValue) return current
  ...

@xaviergonz
Copy link
Contributor Author

@k-g-a thanks for the review! all requested changes done :)

Copy link
Member

@mweststrate mweststrate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

@mweststrate mweststrate removed the require('@mweststrate') @mweststrate input is required! label Oct 23, 2018
@mweststrate
Copy link
Member

Feel free to release :-)

@xaviergonz
Copy link
Contributor Author

minor or patch? asking because it is a feature-bugfix

@xaviergonz xaviergonz merged commit 4378139 into master Oct 23, 2018
@mweststrate
Copy link
Member

mweststrate commented Oct 23, 2018 via email

@xaviergonz xaviergonz deleted the fix-1052 branch November 25, 2018 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug enhancement Possible enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants