Permalink
Browse files

Simplify recordCache

  • Loading branch information...
wycats committed Jun 8, 2012
1 parent e8916da commit 7d2f84581e7d25b853f9cee21fe8399627472618
@@ -26,43 +26,13 @@ DS.RecordArray = Ember.ArrayProxy.extend({
// The store that created this record array.
store: null,
- init: function() {
- this.contentWillChange();
- this._super();
- },
-
- contentWillChange: Ember.beforeObserver(function() {
- set(this, 'recordCache', []);
- }, 'content'),
-
- contentArrayDidChange: function(array, index, removed, added) {
- var recordCache = get(this, 'recordCache');
- var args = [index, 0].concat(new Array(added));
-
- recordCache.splice.apply(recordCache, args);
- },
-
- contentArrayWillChange: function(array, index, removed, added) {
- var recordCache = get(this, 'recordCache');
- recordCache.splice(index, removed);
- },
-
objectAtContent: function(index) {
- var recordCache = get(this, 'recordCache');
- var record = recordCache[index];
-
- if (!record) {
- var store = get(this, 'store');
- var content = get(this, 'content');
+ var content = get(this, 'content'),
+ clientId = content.objectAt(index),
+ store = get(this, 'store');
- var contentObject = content.objectAt(index);
-
- if (contentObject !== undefined) {
- record = store.findByClientId(get(this, 'type'), contentObject);
- recordCache[index] = record;
- }
+ if (clientId !== undefined) {
+ return store.findByClientId(get(this, 'type'), clientId);
}
-
- return record;
}
});
@@ -305,8 +305,7 @@ DS.Store = Ember.Object.extend({
findByClientId: function(type, clientId, id) {
var recordCache = get(this, 'recordCache'),
- dataCache = this.typeMapFor(type).cidToHash,
- record;
+ dataCache, record;
// If there is already a clientId assigned for this
// type/id combination, try to find an existing
@@ -321,6 +320,8 @@ DS.Store = Ember.Object.extend({
// 'isLoading' state
record = this.materializeRecord(type, clientId);
+ dataCache = this.typeMapFor(type).cidToHash;
+
if (typeof dataCache[clientId] === 'object') {
record.send('didChangeData');
}
@@ -385,11 +385,11 @@ test("a record array that backs a collection view functions properly", function(
function compareArrays() {
var recordArray = container.content;
- var recordCache = recordArray.get('recordCache');
+ var recordCache = store.get('recordCache');
var content = recordArray.get('content');
for(var i = 0; i < content.length; i++) {
- var record = recordCache[i];
var clientId = content.objectAt(i);
+ var record = recordCache[clientId];
equal(record && record.clientId, clientId, "The entries in the record cache should have matching client ids.");
}
}

0 comments on commit 7d2f845

Please sign in to comment.