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

Commit 0e44ac2

Browse files
committed
refactor(hashKey): don't generate memory garbage
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
1 parent 5a1a0c9 commit 0e44ac2

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/apis.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,23 @@
1414
* The resulting string key is in 'type:hashKey' format.
1515
*/
1616
function hashKey(obj, nextUidFn) {
17-
var objType = typeof obj,
18-
key;
17+
var key = obj && obj.$$hashKey;
1918

20-
if (objType == 'function' || (objType == 'object' && obj !== null)) {
21-
if (typeof (key = obj.$$hashKey) == 'function') {
22-
// must invoke on object to keep the right this
19+
if (key) {
20+
if (typeof key === 'function') {
2321
key = obj.$$hashKey();
24-
} else if (key === undefined) {
25-
key = obj.$$hashKey = (nextUidFn || nextUid)();
2622
}
23+
return key;
24+
}
25+
26+
var objType = typeof obj;
27+
if (objType == 'function' || (objType == 'object' && obj !== null)) {
28+
key = obj.$$hashKey = objType + ':' + (nextUidFn || nextUid)();
2729
} else {
28-
key = obj;
30+
key = objType + ':' + obj;
2931
}
3032

31-
return objType + ':' + key;
33+
return key;
3234
}
3335

3436
/**

0 commit comments

Comments
 (0)