Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
refactor(hashKey): don't generate memory garbage
Browse files Browse the repository at this point in the history
we now store both the object type and the id as the hashkey and return it for all objects.

for primitives we still have to do string concatination because we can't use expandos on them to
store the hashkey
  • Loading branch information
IgorMinar committed Aug 26, 2014
1 parent 5a1a0c9 commit 0e44ac2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@
* The resulting string key is in 'type:hashKey' format.
*/
function hashKey(obj, nextUidFn) {
var objType = typeof obj,
key;
var key = obj && obj.$$hashKey;

if (objType == 'function' || (objType == 'object' && obj !== null)) {
if (typeof (key = obj.$$hashKey) == 'function') {
// must invoke on object to keep the right this
if (key) {
if (typeof key === 'function') {
key = obj.$$hashKey();
} else if (key === undefined) {
key = obj.$$hashKey = (nextUidFn || nextUid)();
}
return key;
}

var objType = typeof obj;
if (objType == 'function' || (objType == 'object' && obj !== null)) {
key = obj.$$hashKey = objType + ':' + (nextUidFn || nextUid)();
} else {
key = obj;
key = objType + ':' + obj;
}

return objType + ':' + key;
return key;
}

/**
Expand Down

0 comments on commit 0e44ac2

Please sign in to comment.