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 release] ArrayProxy#content should not be a computed property #12860

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions packages/ember-runtime/lib/system/array_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,7 @@ var ArrayProxy = EmberObject.extend(MutableArray, {
@type Ember.Array
@private
*/
content: computed({
get() {
return this._content;
},
set(k, v) {
if (this._didInitArrayProxy) {
var oldContent = this._content;
var len = oldContent ? get(oldContent, 'length') : 0;
this.arrangedContentArrayWillChange(this, 0, len, undefined);
this.arrangedContentWillChange(this);
}
this._content = v;
return v;
}
}),


content: null,

/**
The array that the proxy pretends to be. In the default `ArrayProxy`
Expand Down Expand Up @@ -179,12 +163,16 @@ var ArrayProxy = EmberObject.extend(MutableArray, {
@method _contentDidChange
*/
_contentDidChange: observer('content', function() {
var content = get(this, 'content');
this._teardownContent(this._prevContent);
let prevContent = this._prevContent;
let content = get(this, 'content');

assert('Can\'t set ArrayProxy\'s content to itself', content !== this);
if (content !== prevContent) {
this._teardownContent(prevContent);

this._setupContent();
assert('Can\'t set ArrayProxy\'s content to itself', content !== this);

this._setupContent();
}
}),

_setupContent() {
Expand Down Expand Up @@ -369,7 +357,6 @@ var ArrayProxy = EmberObject.extend(MutableArray, {
},

init() {
this._didInitArrayProxy = true;
this._super(...arguments);
this._setupContent();
this._setupArrangedContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,6 @@ QUnit.test('should update length for null content when there is a computed prope
equal(proxy.get('length'), 0, 'length updates');
});

QUnit.test('The `arrangedContentWillChange` method is invoked before `content` is changed.', function() {
var callCount = 0;
var expectedLength;

var proxy = ArrayProxy.extend({
arrangedContentWillChange() {
equal(this.get('arrangedContent.length'), expectedLength, 'hook should be invoked before array has changed');
callCount++;
}
}).create({ content: emberA([1, 2, 3]) });

proxy.pushObject(4);
equal(callCount, 0, 'pushing content onto the array doesn\'t trigger it');

proxy.get('content').pushObject(5);
equal(callCount, 0, 'pushing content onto the content array doesn\'t trigger it');

expectedLength = 5;
proxy.set('content', emberA(['a', 'b']));
equal(callCount, 1, 'replacing the content array triggers the hook');
});

QUnit.test('The `arrangedContentDidChange` method is invoked after `content` is changed.', function() {
var callCount = 0;
var expectedLength;
Expand Down