Skip to content

Commit

Permalink
Merge pull request #14117 from mmun/call-array-proxy-content-change-h…
Browse files Browse the repository at this point in the history
…ooks

[BUGFIX beta] Call ArrayProxy's content change hooks
  • Loading branch information
rwjblue authored Aug 26, 2016
2 parents ac07da7 + 0c2a3f0 commit b70c72d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
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);
});

0 comments on commit b70c72d

Please sign in to comment.