Skip to content

Commit

Permalink
Notify the RecordArray once it has been loaded from Server
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleypriest committed Sep 4, 2012
1 parent dad611c commit 61cd16a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/ember-data/lib/adapters/fixture_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ DS.FixtureAdapter = DS.Adapter.extend({

this.simulateRemoteCall(function() {
store.loadMany(type, fixtures);
store.typeMapFor(type).findAllCache.set('didFindAllRecords', true);
}, store, type);
},

Expand Down
1 change: 1 addition & 0 deletions packages/ember-data/lib/adapters/rest_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ DS.RESTAdapter = DS.Adapter.extend({
success: function(json) {
this.sideload(store, type, json, plural);
store.loadMany(type, json[plural]);
store.typeMapFor(type).findAllCache.set('didFindAllRecords', true);
}
});
},
Expand Down
3 changes: 3 additions & 0 deletions packages/ember-data/lib/system/record_arrays/record_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ DS.RecordArray = Ember.ArrayProxy.extend({
// The store that created this record array.
store: null,

// Has the recordArray been loaded via findAll.
didFindAllRecords: false,

objectAtContent: function(index) {
var content = get(this, 'content'),
clientId = content.objectAt(index),
Expand Down
13 changes: 13 additions & 0 deletions packages/ember-data/tests/unit/rest_adapter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,19 @@ test("finding all people makes a GET to /people", function() {
equal(person, store.find(Person, 1), "the record is now in the store, and can be looked up by ID without another Ajax request");
});

test("finding all sets the recordArray's didFindAllRecords flag", function() {
people = store.find(Person);

equal(false, people.get('didFindAllRecords'), "didFindAllRecords is initially false");

expectUrl("/people", "the plural of the model name");
expectType("GET");

ajaxHash.success({ people: [{ id: 1, name: "Yehuda Katz" }] });

equal(true, people.get('didFindAllRecords'), "The RecordArray was informed of the successful request");
});

test("finding all can sideload data", function() {
var groups = store.find(Group);

Expand Down

0 comments on commit 61cd16a

Please sign in to comment.