MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / traverseAllChildrenImpl

Function traverseAllChildrenImpl

code/styling/public/app.js:19048–19124  ·  view source on GitHub ↗

* @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 {!number} The nu

(children, nameSoFar, callback, traverseContext)

Source from the content-addressed store, hash-verified

19046 * @return {!number} The number of children in this subtree.
19047 */
19048function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) {
19049 var type = typeof children;
19050
19051 if (type === 'undefined' || type === 'boolean') {
19052 // All of the above are perceived as null.
19053 children = null;
19054 }
19055
19056 var invokeCallback = false;
19057
19058 if (children === null) {
19059 invokeCallback = true;
19060 } else {
19061 switch (type) {
19062 case 'string':
19063 case 'number':
19064 invokeCallback = true;
19065 break;
19066 case 'object':
19067 switch (children.$$typeof) {
19068 case REACT_ELEMENT_TYPE:
19069 case REACT_PORTAL_TYPE:
19070 invokeCallback = true;
19071 }
19072 }
19073 }
19074
19075 if (invokeCallback) {
19076 callback(traverseContext, children,
19077 // If it's the only child, treat the name as if it was wrapped in an array
19078 // so that it's consistent if the number of children grows.
19079 nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar);
19080 return 1;
19081 }
19082
19083 var child = void 0;
19084 var nextName = void 0;
19085 var subtreeCount = 0; // Count of children found in the current subtree.
19086 var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
19087
19088 if (Array.isArray(children)) {
19089 for (var i = 0; i < children.length; i++) {
19090 child = children[i];
19091 nextName = nextNamePrefix + getComponentKey(child, i);
19092 subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
19093 }
19094 } else {
19095 var iteratorFn = getIteratorFn(children);
19096 if (typeof iteratorFn === 'function') {
19097 {
19098 // Warn about using Maps as children
19099 if (iteratorFn === children.entries) {
19100 warning(didWarnAboutMaps, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', ReactDebugCurrentFrame.getStackAddendum());
19101 didWarnAboutMaps = true;
19102 }
19103 }
19104
19105 var iterator = iteratorFn.call(children);

Callers 1

traverseAllChildrenFunction · 0.70

Calls 4

warningFunction · 0.85
getComponentKeyFunction · 0.70
getIteratorFnFunction · 0.70
invariantFunction · 0.70

Tested by

no test coverage detected