-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: @attr defaultValue() results should persist after initialization #9355
Merged
runspired
merged 5 commits into
emberjs:main
from
christophersansone:fix/default-value-attr-persists
May 10, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
41c6e0c
defaultValue function results should persist after initialization
d788966
defaultValue function results should persist after initialization
2e38bed
clear default values on patch changes
f96cb82
defaultValue caching test
444511f
Merge branch 'main' into fix/default-value-attr-persists
christophersansone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we also need to clear defaultAttrs during patchLocalAttributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick feedback!
I reviewed
patchLocalAttributes
and happy to make the change, but feel like I need a bit more clarification. FWICT, the purpose of that method is to simply remove the key/value pairs fromlocalAttrs
that are not inremoteAttrs
orinflightAttrs
. I'm assuming this would occur when, say, a record is updated from the server while there are still local changes? If so, should we also have similar logic to remove anydefaultAttrs
that have keys present inlocalAttrs
,remoteAttrs
, orinflightAttrs
?The way I see it, yes it might be worthwhile to ensure
defaultAttrs
is kept clean at every possible chance, but because the order of operations ofgetAttr
would inherently prevent a default value from being exposed if any of the other sets of attributes contains that key, it could be considered superfluous.In thinking through the scenario, if I understand it correctly:
defaultValue
function, so the default value is created.This seems like quite an edge case, but I think my opinion would be that the original default value would take effect again, as opposed to a new one being created.
Happy to do what you think makes the most sense here, just let me know!
Also, I was hoping to find a nice set of unit tests for this cache class, but no luck 😕. Do you have a recommendation regarding where to write some tests for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the server has previously informed us of a state, and that state later disappears, imo the correct thing to do is start over.
The cache requires integration tests. Newest ones are here https://github.com/emberjs/data/tree/main/tests/ember-data__json-api/tests/integration/cache and here https://github.com/emberjs/data/blob/main/tests/main/tests/integration/cache/json-api-cache-test.js
but most of them are scattered through the main test app, with most having been written from the perspective of user observable behaviors (due largely to how cache grew out of Store/Model/InternalModel).
I'd recommend adding new tests at that first link above since this is a behavior specific to JSON:API cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@christophersansone got any more time for this one? I can poke at it a bit if needed