Skip to content

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

Merged
rwjblue merged 1 commit into
emberjs:masterfrom
rwjblue:moar-array-proxy-tweaks
Jun 28, 2018
Merged

rwjblue merged 1 commit into
emberjs:masterfrom
rwjblue:moar-array-proxy-tweaks

Conversation

@rwjblue

@rwjblue rwjblue commented Jun 28, 2018 •

Copy link
Copy Markdown
Member

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

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

Copy link
Copy Markdown
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
Copy Markdown
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 force-pushed the moar-array-proxy-tweaks branch from c081c09 to 7189bf0 Compare June 28, 2018 17:52
@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.

2 participants