Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
Commits on Jun 04, 2012
Mike Andrzejewski sideloaded data should be loaded prior to primary data eded501
@tomdale tomdale Merge pull request #272 from MikeAndrzejewski/master
Sideloaded data should be loaded prior to primary data
228d78f
Tom Dale Filteres shouldn't include deleted records
RecordArrays that are filtered should not include
deleted records.
233af19
View
8 packages/ember-data/lib/adapters/rest_adapter.js
@@ -122,8 +122,8 @@ DS.RESTAdapter = DS.Adapter.extend({
this.ajax(this.buildURL(root, id), "GET", {
success: function(json) {
- store.load(type, json[root]);
this.sideload(store, type, json, root);
+ store.load(type, json[root]);
}
});
},
@@ -134,8 +134,8 @@ DS.RESTAdapter = DS.Adapter.extend({
this.ajax(this.buildURL(root), "GET", {
data: { ids: ids },
success: function(json) {
- store.loadMany(type, json[plural]);
this.sideload(store, type, json, plural);
+ store.loadMany(type, json[plural]);
}
});
},
@@ -145,8 +145,8 @@ DS.RESTAdapter = DS.Adapter.extend({
this.ajax(this.buildURL(root), "GET", {
success: function(json) {
- store.loadMany(type, json[plural]);
this.sideload(store, type, json, plural);
+ store.loadMany(type, json[plural]);
}
});
},
@@ -157,8 +157,8 @@ DS.RESTAdapter = DS.Adapter.extend({
this.ajax(this.buildURL(root), "GET", {
data: query,
success: function(json) {
- recordArray.load(json[plural]);
this.sideload(store, type, json, plural);
+ recordArray.load(json[plural]);
}
});
},
View
13 packages/ember-data/lib/system/store.js
@@ -618,21 +618,28 @@ DS.Store = Ember.Object.extend({
clientIds = typeMap.clientIds,
clientId, hash, proxy;
- var recordCache = get(this, 'recordCache'), record;
+ var recordCache = get(this, 'recordCache'),
+ foundRecord,
+ record;
for (var i=0, l=clientIds.length; i<l; i++) {
clientId = clientIds[i];
+ foundRecord = false;
hash = dataCache[clientId];
if (typeof hash === 'object') {
if (record = recordCache[clientId]) {
- proxy = get(record, 'data');
+ if (!get(record, 'isDeleted')) {
+ proxy = get(record, 'data');
+ foundRecord = true;
+ }
} else {
DATA_PROXY.savedData = hash;
proxy = DATA_PROXY;
+ foundRecord = true;
}
- this.updateRecordArray(array, filter, type, clientId, proxy);
+ if (foundRecord) { this.updateRecordArray(array, filter, type, clientId, proxy); }
}
}
},
View
29 packages/ember-data/tests/unit/record_array_test.js
@@ -118,16 +118,41 @@ test("a record array returns undefined when asking for a member outside of its c
strictEqual(recordArray.objectAt(20), undefined, "objects outside of the range just return undefined");
});
+var shouldContain = function(array, item) {
+ ok(array.indexOf(item) !== -1, "array should contain "+item.get('name'));
+};
+
+var shouldNotContain = function(array, item) {
+ ok(array.indexOf(item) === -1, "array should not contain "+item.get('name'));
+};
+
test("a Record Array can update its filter", function() {
- var store = DS.Store.create();
+ var store = DS.Store.create({
+ adapter: DS.Adapter.create({
+ deleteRecord: function(store, type, record) {
+ store.didDeleteRecord(record);
+ }
+ })
+ });
store.loadMany(Person, array);
+ var dickens = store.createRecord(Person, { id: 4, name: "Scumbag Dickens" });
+ dickens.deleteRecord();
+ store.commit();
+
+ var dale = store.find(Person, 1);
+ var katz = store.find(Person, 2);
+ var bryn = store.find(Person, 3);
+
var recordArray = store.filter(Person, function(hash) {
if (hash.get('name').match(/Scumbag [KD]/)) { return true; }
});
- equal(get(recordArray, 'length'), 2, "The Record Array should have the filtered objects on it");
+ shouldContain(recordArray, dale);
+ shouldContain(recordArray, katz);
+ shouldNotContain(recordArray, bryn);
+ shouldNotContain(recordArray, dickens);
recordArray.set('filterFunction', function(hash) {
if (hash.get('name').match(/Katz/)) { return true; }
View
15 packages/ember-data/tests/unit/rest_adapter_test.js
@@ -802,3 +802,18 @@ test("if you specify a namespace then it is prepended onto all URLs", function()
store.load(Person, { id: 1 });
});
+test("sideloaded data is loaded prior to primary data (to ensure relationship coherence)", function() {
+ expect(1);
+
+ group = store.find(Group, 1);
+ group.on("didLoad", function() {
+ equal(group.getPath('people.firstObject').get('name'), "Tom Dale", "sideloaded data are already loaded");
+ });
+
+ ajaxHash.success({
+ people: [
+ { id: 1, name: "Tom Dale" }
+ ],
+ group: { id: 1, name: "Tilde team", people: [1] }
+ });
+});

No commit comments for this range

Something went wrong with that request. Please try again.