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] Fetch cancels unload #5376

Merged
merged 1 commit into from
Mar 14, 2018
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
12 changes: 12 additions & 0 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,18 @@ Store = Service.extend({
seeking[internalModel.id] = pendingItem;
}

for (let i = 0; i < totalItems; i++) {
let internalModel = internalModels[i];
// We may have unloaded the record after scheduling this fetch, in which
// case we must cancel the destory. This is because we require a record
// to build a snapshot. This is not fundamental: this cancelation code
// can be removed when snapshots can be created for internal models that
// have no records.
if (internalModel.hasScheduledDestroy()) {
internalModels[i].cancelDestroy();
}
}

function _fetchRecord(recordResolverPair) {
let recordFetch = store._fetchRecord(
recordResolverPair.internalModel,
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/records/unload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2089,3 +2089,31 @@ test('unload invalidates link promises', function(assert) {
})
);
});

test('fetching records cancels unloading', function(assert) {
env.adapter.findRecord = (store, type, id) => {
assert.equal(type, Person, 'findRecord(_, type) is correct');
assert.deepEqual(id, '1', 'findRecord(_, _, id) is correct');

return {
data: {
id: 1,
type: 'person'
}
}
};

run(() =>
env.store.push({
data: {
id: 1,
type: 'person'
}
})
);

return run(() =>
env.store.findRecord('person', 1, { backgroundReload: true })
.then(person => person.unloadRecord())
);
});