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 beta] Call ArrayProxy's content change hooks #14117

Merged
merged 1 commit into from
Aug 26, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/ember-runtime/lib/system/array_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import alias from 'ember-metal/alias';
import {
addArrayObserver,
removeArrayObserver,
arrayContentDidChange,
arrayContentWillChange,
objectAt
} from 'ember-runtime/mixins/array';

Expand Down Expand Up @@ -374,11 +372,11 @@ export default EmberObject.extend(MutableArray, {
},

arrangedContentArrayWillChange(item, idx, removedCnt, addedCnt) {
arrayContentWillChange(this, idx, removedCnt, addedCnt);
this.arrayContentWillChange(idx, removedCnt, addedCnt);
},

arrangedContentArrayDidChange(item, idx, removedCnt, addedCnt) {
arrayContentDidChange(this, idx, removedCnt, addedCnt);
this.arrayContentDidChange(idx, removedCnt, addedCnt);
},

init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,32 @@ QUnit.test('lastObject - returns last arranged object', function() {
QUnit.test('firstObject - returns first arranged object', function() {
equal(array.get('firstObject'), '5', 'returns first arranged object');
});

QUnit.test('arrangedContentArray{Will,Did}Change are called when the arranged content changes', function() {
// The behaviour covered by this test may change in the future if we decide
// that built-in array methods are not overridable.

let willChangeCallCount = 0;
let didChangeCallCount = 0;

let content = emberA([1, 2, 3]);
ArrayProxy.extend({
arrangedContentArrayWillChange() {
willChangeCallCount++;
this._super(...arguments);
},
arrangedContentArrayDidChange() {
didChangeCallCount++;
this._super(...arguments);
}
}).create({ content });

equal(willChangeCallCount, 0);
equal(didChangeCallCount, 0);

content.pushObject(4);
content.pushObject(5);

equal(willChangeCallCount, 2);
equal(didChangeCallCount, 2);
});
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,32 @@ QUnit.test('The ArrayProxy doesn\'t explode when assigned a destroyed object', f

ok(true, 'No exception was raised');
});

QUnit.test('arrayContent{Will,Did}Change are called when the content changes', function() {
// The behaviour covered by this test may change in the future if we decide
// that built-in array methods are not overridable.

let willChangeCallCount = 0;
let didChangeCallCount = 0;

let content = emberA([1, 2, 3]);
ArrayProxy.extend({
arrayContentWillChange() {
willChangeCallCount++;
this._super(...arguments);
},
arrayContentDidChange() {
didChangeCallCount++;
this._super(...arguments);
}
}).create({ content });

equal(willChangeCallCount, 0);
equal(didChangeCallCount, 0);

content.pushObject(4);
content.pushObject(5);

equal(willChangeCallCount, 2);
equal(didChangeCallCount, 2);
});