Permalink
Browse files

moved the DS.RecordArray creation of Store#all(type) into a separate

function to allow the user to override and supply a derived
DS.RecordArray type.
  • Loading branch information...
1 parent faef5bf commit 1041eedfee37f5f3d7c45f37bc209ae9f94eac30 @dagda1 committed Nov 7, 2012
Showing with 31 additions and 1 deletion.
  1. +12 −1 packages/ember-data/lib/system/store.js
  2. +19 −0 packages/ember-data/tests/unit/store_test.js
@@ -722,14 +722,25 @@ DS.Store = Ember.Object.extend(DS.Mappable, {
if (findAllCache) { return findAllCache; }
- var array = DS.RecordArray.create({ type: type, content: Ember.A([]), store: this, isLoaded: true });
+ var array = this.newRecordArray(type);
+ Ember.assert("You can only register an instance or subclass of DS.RecordArray", array instanceof DS.RecordArray);
+
this.registerRecordArray(array, type);
typeMap.findAllCache = array;
return array;
},
/**
+ * Override to supply a subclass of DS.RecordArray
+ @param {Class} type
+ @return {DS.RecordArray}
+ **/
+ newRecordArray: function(type){
+ return DS.RecordArray.create({ type: type, content: Ember.A([]), store: this, isLoaded: true });
+ },
+
+ /**
Takes a type and filter function, and returns a live RecordArray that
remains up to date as new records are loaded into the store or created
locally.
@@ -392,6 +392,25 @@ test("all(type) returns a record array of all records of a specific type", funct
strictEqual(results, store.all(Person), "subsequent calls to all return the same recordArray)");
});
+test("all(type) can return a subclass of RecordArray", function(){
+ var DerivedRecordArray = DS.RecordArray.extend();
+
+ var store = DS.Store.create({
+ adapter: DS.Adapter.create(),
+ newRecordArray: function(type){
+ return DerivedRecordArray.create({type: type, content: Ember.A([]), store: this});
+ }
+ });
+
+ var Person = DS.Model.extend({
+ name: DS.attr('string')
+ });
+
+ var array = store.all(Person);
+
+ equal(array.constructor, DerivedRecordArray, "Subclass of RecordArray returned from all");
+});
+
test("a new record of a particular type is created via store.createRecord(type)", function() {
var store = DS.Store.create();
var Person = DS.Model.extend({

0 comments on commit 1041eed

Please sign in to comment.