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

Allow getFieldValue to read from foreign Reference objects. #5651

Merged
merged 1 commit into from
Dec 4, 2019

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Dec 3, 2019

The getFieldValue(fieldName) helper function was introduced in #5617 for reading fields from the current StoreObject during read functions.

This commit adds a second parameter to getFieldValue, foreignRef, which is an optional Reference. When foreignRef is provided, getFieldValue will read the specified field from the StoreObject identified by the foreignRef, instead of reading from the current StoreObject.

In either case, getFieldValue reads an existing value from the cache, without invoking any read functions, so you cannot use getFieldValue to set up expensive (and potentially cyclic) chains of read functions.

With this new ability to read fields from arbitrary Reference objects, read functions can explore the entire reachable cache without having to call cache.readQuery. The beauty of this system is that every field reading operation requires a function call (getFieldValue), which allows the result caching system to know which fields were read from which entities, so future changes to those fields can properly invalidate any cached results that involved the original read function.

I recommend reading through the included tests to get a concrete sense for how everything works.

The getFieldValue(fieldName) helper function was introduced in #5617 for
reading fields from the current StoreObject during read functions.

This commit adds a second parameter to getFieldValue, foreignRef, which is
an optional Reference. When foreignRef is provided, getFieldValue will
read the specified field from the StoreObject identified by the
foreignRef, instead of reading from the current StoreObject.

In either case, getFieldValue reads an existing value from the cache,
without invoking any read functions, so you cannot use getFieldValue to
set up expensive (and potentially cyclic) chains of read functions.

With this new ability to read fields from arbitrary Reference objects,
read functions can explore the entire reachable cache, without having to
call cache.readQuery. The beauty of this system is that every field read
operation requires a function call (getFieldValue), which allows the
result caching system to know which fields were read from which entities,
so future changes to those fields can properly invalidate any cached
results that involved the original read function.
@benjamn benjamn added this to the Release 3.0 milestone Dec 3, 2019
@benjamn benjamn self-assigned this Dec 3, 2019
@benjamn benjamn mentioned this pull request Dec 4, 2019
31 tasks
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

Very cool (and useful) @benjamn!

@benjamn benjamn merged commit 5314cba into release-3.0 Dec 4, 2019
@benjamn benjamn deleted the getFieldValue-foreignRef-parameter branch December 4, 2019 14:14
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants