Skip to content

Commit

Permalink
Merge pull request #4529 from wongpeiyi/fix-isUpdating-without-reload
Browse files Browse the repository at this point in the history
isUpdating should be true only if a reload happens
  • Loading branch information
bmac authored Oct 4, 2016
2 parents 5ab07db + c12fff9 commit 2926c47
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 3 additions & 2 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1431,15 +1431,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 @@ -1448,6 +1448,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);
});

0 comments on commit 2926c47

Please sign in to comment.