-
-
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
unloadRecord does not remove observers #4277
unloadRecord does not remove observers #4277
Conversation
@ryanpatrickcook I believe unloadRecord should destroy the object and clear observers. |
That is what I would think as well, but it doesn't appear to be clearing observers. There is a twiddle in the issue linked that shows an example. In the test written here, it also appears that |
Hey @ryanpatrickcook, this has been discussed in this weeks' team meeting and we decided that the record should indeed be destroyed when it's unloaded. Sorry for the delay, but can you update this PR to do the following:
After those changes the test should be green and this should be good to go! 🚀 |
@ryanpatrickcook do you think you have time to update this PR? Happy to help or take over if you won't have time in the near future... |
c9bab2e
to
9788587
Compare
@pangratz I've updated with your input. Let me know what you think. Thanks! |
9788587
to
c7b827f
Compare
@@ -86,7 +86,7 @@ test("unload a record", function(assert) { | |||
store.unloadRecord(record); | |||
}); | |||
|
|||
assert.equal(get(record, 'hasDirtyAttributes'), false, "record is not dirty"); |
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.
Using Ember 1.13.13, after a record was unloaded/destroyed, get(record, 'hasDirtyAttributes')
returned undefined
. Since the record was now destroyed, I felt as though checking hasDirtyAttributes
was no longer valid. Replaced with an isDestroyed
check. Would it be preferred that hasDirtyAttributes
responds with false
?
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.
Hmm, not sure what the expected behavior of hasDirtyAttributes
is here. I will bring this up in the next meeting. Good point @ryanpatrickcook 👍
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 just checked and it seems that hasDirtyAttributes
is false
after a record is destroyed (both for 1.13
and 2.5
). See this ember-twiddle. Am I missing something?
I think in this case it would be ok to add back the assertion for hasDirtyAttributes
...
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.
In 1.13
, it looks like if the assertion for hasDirtyAttributes
is undefined
when outside of the run-loop with unloadRecord
. When inside the run-loop with unloadRecord
, it returns false
.
c7b827f
to
51fdcd6
Compare
}); | ||
|
||
assert.equal(get(record, 'hasDirtyAttributes'), false, "record is not dirty"); |
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 reason this assertion is failing is due to the implementation of hasDirtyAttributes
in DS.Model
. It looks like a change to the currentState.isDirty
dependency of the computed property is triggered when the record is unloaded.
@emberjs/ember-data-contributors are there any objections in changing the implementation so it re-uses the retrieveFromCurrentState
function, like we already do for the other flags like isDirty
?
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.
@ryanpatrickcook so, we decided to change the implementation of the hasDirtyAttributes
CP on the model, by aligning it to the implementation of the other flags. Can you change the dependent key here to be just currentState
and add back the assertion. After that, this PR is good to go!
51fdcd6
to
9ab9c07
Compare
hasDirtyAttributes: Ember.computed('currentState.isDirty', function() { | ||
return this.get('currentState.isDirty'); | ||
hasDirtyAttributes: Ember.computed('currentState', function() { | ||
return this.get('_internalModel.currentState.isDirty'); |
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.
@pangratz I updated the dependent key in the CP here to currentState
, but the hasDirtyAttributes
assertion still failed in 1.13
since this.get('currentState')
is undefined
. I updated the returned value to _internalModel.currentState.isDirty
similar to what retrieveFromCurrentState
is doing. Will this work?
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.
How did you test this? Because we have an ember-try
scenario for ember.js 1.13 and it looks like the test passes on Travis and AppVeyor.
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.
@pangratz I switched the return back to this.get('currentState.isDirty')
. Note the current failure on the branch. I think this should be returning this.get('_internalModel.currentState.isDirty')
. In my previous question I was just wanting to verify with you that it was appropriate to refer to _internalModel.currentState.isDirty
. That may have been confusing.
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.
Ah, now I see. Sorry for being slow here. Re-reading your comment makes it clear what you meant. Yes, please change it back to this.get('_internalModel.currentState.isDirty')
. Thanks!
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.
Great! Thanks!
056a72c
to
b38609f
Compare
I think this is still relevant. @ryanpatrickcook can you rebase onto the latest master, and @pangratz can you take another look? |
destroyed and observers removed
b38609f
to
00e954c
Compare
Sorry this took so long @ryanpatrickcook. Thanks for your patience and this fix! |
Issue: #4126
This is a work in progress to get conversation going on what the expectation should be. The test shows the issue where when you unload a record from the store, the observers on that object are not torn down.
unloadRecord
set the object as destroyed?unloadRecord
clear observers?