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

Data Adapter: Only trigger model type update if the record live array count actually changed #15604

Merged
merged 1 commit into from
Oct 4, 2017
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
8 changes: 6 additions & 2 deletions packages/ember-extension-support/lib/data_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,12 @@ export default EmberObject.extend({
}

let observer = {
didChange() {
run.scheduleOnce('actions', this, onChange);
didChange(array, idx, removedCount, addedCount) {
// Only re-fetch records if the record count changed
// (which is all we care about as far as model types are concerned).
if (removedCount > 0 || addedCount > 0) {
run.scheduleOnce('actions', this, onChange);
}
},
willChange() { return this; }
};
Expand Down
27 changes: 27 additions & 0 deletions packages/ember-extension-support/tests/data_adapter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,33 @@ moduleFor('Data Adapter', class extends ApplicationTestCase {
});
}

['@test Model Types Updated but Unchanged Do not Trigger Callbacks']() {
expect(0);
let records = emberA([1, 2, 3]);
this.add('data-adapter:main', DataAdapter.extend({
getRecords(klass, name) {
return records;
}
}));
this.add('model:post', PostClass);

return this.visit('/').then(() => {
adapter = this.applicationInstance.lookup('data-adapter:main');

function modelTypesAdded(types) {
run(() => {
records.arrayContentDidChange(0, 0, 0);
});
}

function modelTypesUpdated(types) {
ok(false, "modelTypesUpdated should not be triggered if the array didn't change");
}

adapter.watchModelTypes(modelTypesAdded, modelTypesUpdated);
});
}

['@test Records Added']() {
let countAdded = 1;
let post = PostClass.create();
Expand Down