Skip to content

Commit

Permalink
Merge pull request #5376 from hjdivad/hjdivad/cancel-unload-on-fetch
Browse files Browse the repository at this point in the history
[bugfix beta] Fetch cancels unload
  • Loading branch information
hjdivad authored Mar 14, 2018
2 parents 872f015 + 7444444 commit bae8df9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
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())
);
});

0 comments on commit bae8df9

Please sign in to comment.