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

[BUGFIX] Setting ArrayProxy#content in willDestroy resets length. #16784

Merged
merged 1 commit into from Jun 28, 2018

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Jun 28, 2018

Prior to this change, ArrayProxy.prototype.length was marked as dirty (and therefore recomputed) when content was set due to arrangedContent being an alias of content, and ArrayProxy implementing PROPERTY_DID_CHANGE to trap arrangedContent changes.

Unfortunately, notifyPropertyChange avoids notifying some things when the object is destroying. This results in the preexisting PROPERTY_DID_CHANGE trap for arrangedContent is no longer called, and therefore length is never marked as dirty.

This fixes the condition, by implementing a content trap in PROPERTY_DID_CHANGE that marks length as dirty. The next time that length is accessed it will do the normal work to recalculate.

/cc @krisselden @runspired

@rwjblue rwjblue requested a review from krisselden June 28, 2018 15:17
@@ -230,6 +230,9 @@ export default class ArrayProxy extends EmberObject {

this.arrayContentDidChange(0, oldLength, newLength);
this._addArrangedContentArrayObsever();
} else if (key === 'content') {
Copy link
Contributor

Choose a reason for hiding this comment

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

at this point we should extract into an invalidate method

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to use a shared _invalidate method.

Prior to this change, `ArrayProxy.prototype.length` was marked as dirty
(and therefore recomputed) when `content` was set due to
`arrangedContent` being an alias of `content`, and `ArrayProxy`
implementing `PROPERTY_DID_CHANGE` to trap `arrangedContent` changes.

Unfortunately, `notifyPropertyChange` avoids notifying _some_ things
when the object is destroying. This results in the preexisting
`PROPERTY_DID_CHANGE` trap for `arrangedContent` is no longer called,
and therefore `length` is never marked as dirty.

This fixes the condition, by implementing a `content` trap in
`PROPERTY_DID_CHANGE` that marks length as dirty. The next time that
`length` is accessed it will do the normal work to recalculate.
@rwjblue rwjblue merged commit 01f5b90 into emberjs:master Jun 28, 2018
@rwjblue rwjblue deleted the moar-array-proxy-tweaks branch June 28, 2018 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants