Skip to content

Commit

Permalink
Modified unregisterChildFromParent so it can safely be called on any
Browse files Browse the repository at this point in the history
storeKey, even if it is not a child record.
  • Loading branch information
Greg Fairbanks authored and publickeating committed Aug 30, 2014
1 parent 356d2e7 commit 6f4377b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
26 changes: 13 additions & 13 deletions frameworks/datastore/system/store.js
Expand Up @@ -1364,7 +1364,7 @@ SC.Store = SC.Object.extend( /** @scope SC.Store.prototype */ {
that.unloadRecord(null, null, storeKey, newStatus);
});

this.unregisterChildFromParent(storeKey, YES);
this.unregisterChildFromParent(storeKey);

return this ;
},
Expand Down Expand Up @@ -1561,26 +1561,26 @@ SC.Store = SC.Object.extend( /** @scope SC.Store.prototype */ {
id = this.idFor(childStoreKey),
that = this;

// Check the child to see if it has a parent
// Check the child to see if it has a parent
childRecords = this.childRecords;

// Remove the parent's connection to the child. This doesn't remove the
// parent store key from the cache of parent store keys if the parent
// no longer has any other registered children, because the amount of effort
// to determine that would not be worth the miniscule memory savings.
// Remove the parent's connection to the child. This doesn't remove the
// parent store key from the cache of parent store keys if the parent
// no longer has any other registered children, because the amount of effort
// to determine that would not be worth the miniscule memory savings.
oldPk = childRecords[childStoreKey];
if (oldPk) {
delete this.parentRecords[oldPk][childStoreKey];
}
}

// Remove the child.
// 1. from the cache of data hashes
// 2. from the cache of record objects
// 3. from the cache of child record store keys
this.removeDataHash(childStoreKey);
// Remove the child.
// 1. from the cache of data hashes
// 2. from the cache of record objects
// 3. from the cache of child record store keys
this.removeDataHash(childStoreKey);
if (this.records) {
delete this.records[childStoreKey];
}
}
delete childRecords[childStoreKey];
}
}
Expand Down
Expand Up @@ -621,15 +621,15 @@ test("Reloading the parent record uses same child record.", function() {

cacheLength = 0;
for (key in store.records) { cacheLength += 1; }
equals(cacheLength, 3, 'there should be three records cached in the store');
equals(cacheLength, 2, 'there should be two records cached in the store');

cacheLength = 0;
for (key in store.dataHashes) { if (store.dataHashes[key] !== null) cacheLength += 1; }
equals(cacheLength, 2, 'there should be two non-null datahashes in the store');

// Reload the record
SC.RunLoop.begin();
store.loadRecord(NestedRecord.ParentRecordTest, {
parentStoreKey = store.loadRecord(NestedRecord.ParentRecordTest, {
name: 'Parent Name 3',
info: {
type: 'ChildRecordTest',
Expand All @@ -640,6 +640,7 @@ test("Reloading the parent record uses same child record.", function() {
parentId);
SC.RunLoop.end();

testParent3 = store.materializeRecord(parentStoreKey);
child = testParent3.get('info');
equals(testParent3.get('status'), SC.Record.READY_CLEAN, 'parent status should be READY_CLEAN');
equals(child.get('status'), SC.Record.READY_CLEAN, 'child status should be READY_CLEAN');
Expand Down

0 comments on commit 6f4377b

Please sign in to comment.