-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Updating references that use internalModel to use recordData #324
Updating references that use internalModel to use recordData #324
Conversation
The only snag that I am currently hitting is with this error showing up in some of the tests:
That error is triggered by the following line: https://github.com/emberjs/data/blob/v3.7.0/addon/-private/system/model/model.js#L1226. It seems to be because the currentState descriptor doesn't have the I have ran this with a debugger statement and then set the |
It seems like this assertion is only triggered when instantiating fragments on record creation. At some point when the fragment is set the |
addon/ext.js
Outdated
|
||
@method rollbackAttributes | ||
*/ | ||
decorateMethod(InternalModelPrototype, 'rollbackAttributes', function rollbackFragments() { |
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.
Deleting this method and moving its functionality into RecordData
. InternalModel now delegates to the rollbackAttributes
method in the recordData
object.
|
||
@method flushChangedAttributes | ||
*/ | ||
decorateMethod(InternalModelPrototype, 'flushChangedAttributes', function flushChangedAttributesFragments() { |
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.
The functionality in this method seems to have been moved to willCommit
|
||
@method adapterDidCommit | ||
*/ | ||
decorateMethod(InternalModelPrototype, 'adapterDidCommit', function adapterDidCommitFragments(returnValue, args) { |
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.
Moved this functionality to recordData
@@ -164,24 +164,23 @@ FragmentRootState = wireState(FragmentRootState, null, 'root'); | |||
export default FragmentRootState; | |||
|
|||
export function fragmentDidDirty(record, key, fragment) { | |||
if (!get(record, 'isDeleted')) { |
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.
This can get called while the record is still being initialized, which causes the DS.Model#currentState
to be overwritten with a new descriptor which then triggers an assertion in the DS.Model#init
method. I am not sure what the consequences of accessing the currentState directly could be. Can we expect it to always be the canonical state?
|
||
// Don't reset if the record is new, otherwise it will enter the 'deleted' state | ||
// NOTE: This case almost never happens with attributes because their initial value | ||
// is always undefined, which is *usually* not what attributes get 'reset' to | ||
if (!get(record, 'isNew')) { | ||
if (!record.currentState.isNew) { |
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.
Any potential issues with accessing currentState
directly? Would using internalModel._currentState
be a better idea?
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.
It seems like it should be ok
@workmanw this looks good to me how about you? |
Now that all the tests are passing I have been testing this against my application. It seems to have introduced an issue where some shared references don't get setup correctly when loading the data. The problem could be because of this update or because of the EmberData upgrade. I can reproduce that behavior with 3.5, 3.6 and 3.7. I'm investigating that issue and I'll update once I've figured out the cause. |
After much debugging I've figured that the issue I was seeing was in my application and was a result of upgrading to EmberData 3.5. It seems like the behavior of inverse relationships is a bit different in EmberData 3.5 and I had to update some relationships that should've been set to null. This gives me added confidence on this PR. It's important to note that this PR breaks compatibility with versions of EmberData before 3.5 and that it may be worth refactoring this to reduce the footprint of the core models that are extended.
@jakesjews @workmanw How do you want to proceed? |
I'm ok with getting this merged then if its needed we can tweak the implementation. @workmanw how about you? |
@jakesjews Looks good to me. I am not concerned about the backwards compat. That comes with the territory for this addon. Thanks a ton for diving in @cohitre . |
@workmanw I think we should release this as version 4 so we don't catch anyone by surprise how about you? |
Merged, wonderful ! when the new version will be available (with README.md update) ? |
Sorry, I'll try to get to this today. I got pulled into a bunch of issues yesterday. |
EmberData 3.5 introduced the
RecordData
object inside theInternalModel
as a way to organize the internal state of models. This made this plugin incompatible with the more recent versions of EmberData #315This PR is a first attempt at updating the plugin to be compatible with EmberData 3.7.
Some of the big changes in EmberData that I've encountered:
recordData
now encapsulates_data
,_attributes
and_inFlightAttributes
: I've updated all of the references to these three objects to go through_recordData
. I've also moved the_fragments
,_owner
and_name
properties into_recordData
for consistency.InternalModel#flushChangedAttributes
method doesn't exist anymore: It seems to have been replaced withwillCommit
, which is then delegated to _recordData. I am overriding willCommit directly on the RecordData prototype.TODO:
currentState
assertion when creating a record with fragments.