Skip to content

Commit

Permalink
allow tests to override array observer detection
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed May 8, 2021
1 parent 744a9b9 commit 96adf26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/-ember-data/tests/unit/many-array-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ module('unit/many_array - DS.ManyArray', function (hooks) {
let willChangeRemoveAmt;
let willChangeAddAmt;

DS.ManyArray.proto().__hasArrayObservers = true;
let originalArrayContentWillChange = DS.ManyArray.proto().arrayContentWillChange;
let originalArrayContentDidChange = DS.ManyArray.proto().arrayContentDidChange;

Expand Down
9 changes: 7 additions & 2 deletions packages/model/addon/-private/system/many-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,14 @@ export default EmberObject.extend(MutableArray, DeprecatedEvented, {
this.retrieveLatest();
},

// TODO refactor away _hasArrayObservers for tests
get _hasArrayObservers() {
return this.hasArrayObservers || this.__hasArrayObservers;
},

notify() {
this._isDirty = true;
if (this.hasArrayObservers) {
if (this._hasArrayObservers) {
this.retrieveLatest();
} else {
this.notifyPropertyChange('[]');
Expand Down Expand Up @@ -255,7 +260,7 @@ export default EmberObject.extend(MutableArray, DeprecatedEvented, {
this._links = jsonApi.links;
}

if (this.hasArrayObservers) {
if (this._hasArrayObservers) {
// diff to find changes
let diff = diffArray(this.currentState, internalModels);
// it's null if no change found
Expand Down

0 comments on commit 96adf26

Please sign in to comment.