* @param {?*} children Children tree container. * @param {!string} nameSoFar Name of the key path so far. * @param {!function} callback Callback to invoke with each child found. * @param {?*} traverseContext Used to pass information throughout the traversal * process. * @return {!numb
(children, nameSoFar, callback, traverseContext)
| 1061 | |
| 1062 | |
| 1063 | function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) { |
| 1064 | var type = typeof children; |
| 1065 | |
| 1066 | if (type === 'undefined' || type === 'boolean') { |
| 1067 | // All of the above are perceived as null. |
| 1068 | children = null; |
| 1069 | } |
| 1070 | |
| 1071 | var invokeCallback = false; |
| 1072 | |
| 1073 | if (children === null) { |
| 1074 | invokeCallback = true; |
| 1075 | } else { |
| 1076 | switch (type) { |
| 1077 | case 'string': |
| 1078 | case 'number': |
| 1079 | invokeCallback = true; |
| 1080 | break; |
| 1081 | |
| 1082 | case 'object': |
| 1083 | switch (children.$$typeof) { |
| 1084 | case REACT_ELEMENT_TYPE: |
| 1085 | case REACT_PORTAL_TYPE: |
| 1086 | invokeCallback = true; |
| 1087 | } |
| 1088 | |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | if (invokeCallback) { |
| 1093 | callback(traverseContext, children, // If it's the only child, treat the name as if it was wrapped in an array |
| 1094 | // so that it's consistent if the number of children grows. |
| 1095 | nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar); |
| 1096 | return 1; |
| 1097 | } |
| 1098 | |
| 1099 | var child; |
| 1100 | var nextName; |
| 1101 | var subtreeCount = 0; // Count of children found in the current subtree. |
| 1102 | |
| 1103 | var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR; |
| 1104 | |
| 1105 | if (Array.isArray(children)) { |
| 1106 | for (var i = 0; i < children.length; i++) { |
| 1107 | child = children[i]; |
| 1108 | nextName = nextNamePrefix + getComponentKey(child, i); |
| 1109 | subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext); |
| 1110 | } |
| 1111 | } else { |
| 1112 | var iteratorFn = getIteratorFn(children); |
| 1113 | |
| 1114 | if (typeof iteratorFn === 'function') { |
| 1115 | |
| 1116 | { |
| 1117 | // Warn about using Maps as children |
| 1118 | if (iteratorFn === children.entries) { |
| 1119 | if (!didWarnAboutMaps) { |
| 1120 | warn('Using Maps as children is deprecated and will be removed in ' + 'a future major release. Consider converting children to ' + 'an array of keyed ReactElements instead.'); |
no test coverage detected