MCPcopy Index your code
hub / github.com/krasimir/react-in-patterns / traverseAllChildrenImpl

Function traverseAllChildrenImpl

code/new-context-api/public/app.js:18409–18485  ·  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

18407 * @return {!number} The number of children in this subtree.
18408 */
18409function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) {
18410 var type = typeof children;
18411
18412 if (type === 'undefined' || type === 'boolean') {
18413 // All of the above are perceived as null.
18414 children = null;
18415 }
18416
18417 var invokeCallback = false;
18418
18419 if (children === null) {
18420 invokeCallback = true;
18421 } else {
18422 switch (type) {
18423 case 'string':
18424 case 'number':
18425 invokeCallback = true;
18426 break;
18427 case 'object':
18428 switch (children.$$typeof) {
18429 case REACT_ELEMENT_TYPE:
18430 case REACT_PORTAL_TYPE:
18431 invokeCallback = true;
18432 }
18433 }
18434 }
18435
18436 if (invokeCallback) {
18437 callback(traverseContext, children,
18438 // If it's the only child, treat the name as if it was wrapped in an array
18439 // so that it's consistent if the number of children grows.
18440 nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar);
18441 return 1;
18442 }
18443
18444 var child = void 0;
18445 var nextName = void 0;
18446 var subtreeCount = 0; // Count of children found in the current subtree.
18447 var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
18448
18449 if (Array.isArray(children)) {
18450 for (var i = 0; i < children.length; i++) {
18451 child = children[i];
18452 nextName = nextNamePrefix + getComponentKey(child, i);
18453 subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
18454 }
18455 } else {
18456 var iteratorFn = getIteratorFn(children);
18457 if (typeof iteratorFn === 'function') {
18458 {
18459 // Warn about using Maps as children
18460 if (iteratorFn === children.entries) {
18461 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());
18462 didWarnAboutMaps = true;
18463 }
18464 }
18465
18466 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