MCPcopy Index your code
hub / github.com/ampproject/amphtml / updateTree_

Method updateTree_

src/core/context/node.js:457–492  ·  view source on GitHub ↗

* @param {?ContextNode<?>} parent * @param {boolean} parentOverridden * @private

(parent, parentOverridden)

Source from the content-addressed store, hash-verified

455 * @private
456 */
457 updateTree_(parent, parentOverridden) {
458 this.parentOverridden_ = parentOverridden;
459
460 const oldParent = this.parent;
461 if (parent != oldParent) {
462 // The parent has changed.
463 this.parent = parent;
464
465 // Remove from the old parent.
466 if (oldParent?.children) {
467 devAssert(oldParent.children);
468 removeItem(oldParent.children, this);
469 }
470
471 // Add to the new parent.
472 if (parent) {
473 const parentChildren = parent.children || (parent.children = []);
474 pushIfNotExist(parentChildren, this);
475
476 // Check if this node has been inserted in between the parent and
477 // it's other children.
478 // Since the new parent (`this`) is already known, this is a very
479 // fast operation.
480 for (const child of parentChildren) {
481 if (child != this && child.isDiscoverable()) {
482 child.discover();
483 }
484 }
485 }
486
487 this.values.parentUpdated();
488 }
489
490 // Check the root.
491 this.updateRoot(parent?.root ?? null);
492 }
493}
494
495/**

Callers 2

setParentMethod · 0.95
discover_Method · 0.95

Calls 7

updateRootMethod · 0.95
devAssertFunction · 0.90
removeItemFunction · 0.90
pushIfNotExistFunction · 0.90
isDiscoverableMethod · 0.80
discoverMethod · 0.80
parentUpdatedMethod · 0.80

Tested by

no test coverage detected