* @param {?ContextNode<?>} parent * @param {boolean} parentOverridden * @private
(parent, parentOverridden)
| 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 | /** |
no test coverage detected