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

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+31 −1
Diff settings

Always

Just for now

@@ -722,13 +722,24 @@ 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.createRecordArray(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}
+ **/
+ createRecordArray: 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
@@ -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(),
+ createRecordArray: 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({