@samitouri / QOS-React-2 / commits / 30f566392b

Extract out wrapUserProvidedKey for clarity

Ben Alpert committed Dec 25, 2013 at 22:32 UTC 30f566392b106f9a9850ae70a37f2cf2e5a5559a
1 file changed +17 -2
src/utils/traverseAllChildren.js
+17 -2
@@ -40,12 +40,23 @@ var invariant = require('invariant');
40 function getComponentKey(component, index) {
41 if (component && component.props && component.props.key != null) {
42 // Explicit key
43 - return '{' + component.props.key + '}';
43 + return wrapUserProvidedKey(component.props.key);
44 }
45 // Implicit key determined by the index in the set
46 return '[' + index + ']';
47 }
48
49 +/**
50 + * Wrap a `key` value explicitly provided by the user to distinguish it from
51 + * implicitly-generated keys generated by a component's index in its parent.
52 + *
53 + * @param {string} key Value of a user-provided `key` attribute
54 + * @return {string}
55 + */
56 +function wrapUserProvidedKey(key) {
57 + return '{' + key + '}';
58 +}
59 +
60 /**
61 * @param {?*} children Children tree container.
62 * @param {!string} nameSoFar Name of the key path so far.
@@ -95,7 +106,11 @@ var traverseAllChildrenImpl =
106 if (children.hasOwnProperty(key)) {
107 subtreeCount += traverseAllChildrenImpl(
108 children[key],
98 - nameSoFar + '{' + key + '}' + getComponentKey(children[key], 0),
109 + (
110 + nameSoFar +
111 + wrapUserProvidedKey(key) +
112 + getComponentKey(children[key], 0)
113 + ),
114 indexSoFar + subtreeCount,
115 callback,
116 traverseContext