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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions packages/ember-runtime/lib/system/array_proxy.js
Expand Up @@ -210,9 +210,7 @@ export default class ArrayProxy extends EmberObject {
if (content) {
replace(content, value, removedCount, added);

this._lengthDirty = true;
this._objectsDirtyIndex = 0;
this._objects = null;
this._invalidate();
}
}

Expand All @@ -225,11 +223,12 @@ export default class ArrayProxy extends EmberObject {
this._removeArrangedContentArrayObsever();
this.arrayContentWillChange(0, oldLength, newLength);

this._objectsDirtyIndex = 0;
this._lengthDirty = true;
this._invalidate();

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.

this._invalidate();
}
}

Expand Down Expand Up @@ -277,6 +276,11 @@ export default class ArrayProxy extends EmberObject {

this.arrayContentDidChange(idx, removedCnt, addedCnt);
}

_invalidate() {
this._objectsDirtyIndex = 0;
this._lengthDirty = true;
}
}

ArrayProxy.reopen(MutableArray, {
Expand Down
18 changes: 18 additions & 0 deletions packages/ember-runtime/tests/system/array_proxy/length_test.js
Expand Up @@ -78,6 +78,24 @@ moduleFor(
assert.deepEqual(obj.content, null, 'content was updated');
}

'@test accessing length after content set to null in willDestroy'(assert) {
let obj = ArrayProxy.extend({
willDestroy() {
this.set('content', null);
this._super(...arguments);
},
}).create({
content: ['foo', 'bar'],
});

assert.equal(obj.length, 2, 'precond');

this.runTask(() => obj.destroy());

assert.equal(obj.length, 0, 'length is 0 without content');
assert.deepEqual(obj.content, null, 'content was updated');
}

'@test setting length to 0'(assert) {
let obj = ArrayProxy.create({ content: ['foo', 'bar'] });

Expand Down