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

isUpdating should be true only if a reload happens #4529

Merged
merged 1 commit into from
Oct 4, 2016
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
5 changes: 3 additions & 2 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1375,15 +1375,15 @@ Store = Service.extend({
assert("You tried to load all records but you have no adapter (for " + typeClass + ")", adapter);
assert("You tried to load all records but your adapter does not implement `findAll`", typeof adapter.findAll === 'function');

set(array, 'isUpdating', true);

if (options.reload) {
set(array, 'isUpdating', true);
return promiseArray(_findAll(adapter, this, typeClass, sinceToken, options));
}

var snapshotArray = array.createSnapshot(options);

if (adapter.shouldReloadAll(this, snapshotArray)) {
set(array, 'isUpdating', true);
return promiseArray(_findAll(adapter, this, typeClass, sinceToken, options));
}

Expand All @@ -1392,6 +1392,7 @@ Store = Service.extend({
}

if (options.backgroundReload || adapter.shouldBackgroundReloadAll(this, snapshotArray)) {
set(array, 'isUpdating', true);
_findAll(adapter, this, typeClass, sinceToken, options);
}

Expand Down
31 changes: 31 additions & 0 deletions tests/integration/adapter/find-all-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,34 @@ test("isUpdating is true while records are fetched in the background", function(
});
});
});

test("isUpdating is false if records are not fetched in the background", function(assert) {
let findAllDeferred = Ember.RSVP.defer();
env.registry.register('adapter:person', DS.Adapter.extend({
findAll() {
return findAllDeferred.promise;
},
shouldReloadAll: () => false,
shouldBackgroundReloadAll: () => false
}));

run(function() {
store.push({
data: [{
type: 'person',
id: 1
}]
});
});

let persons = store.peekAll('person');
assert.equal(persons.get("length"), 1);

run(function() {
store.findAll('person').then(function(persons) {
assert.equal(persons.get("isUpdating"), false);
});
});

assert.equal(persons.get("isUpdating"), false);
});