MCPcopy Create free account
hub / github.com/adobe/react-spectrum / addNode

Method addNode

packages/react-aria/src/collections/Document.ts:469–497  ·  view source on GitHub ↗
(element: ElementNode<T>)

Source from the content-addressed store, hash-verified

467 }
468
469 private addNode(element: ElementNode<T>): void {
470 if (element.isHidden || element.node == null) {
471 return;
472 }
473
474 if (process.env.NODE_ENV !== 'production') {
475 // Two elements with the same key would corrupt the linked list of sibling keys, which
476 // silently drops items or makes key traversal loop forever. Removed and hidden elements
477 // release their key in removeNode before any node is added, so a different owner here
478 // is a live duplicate.
479 let key = element.node.key;
480 let owner = this.keyOwners.get(key);
481 if (owner && owner !== element) {
482 throw new Error(
483 `Duplicate key "${String(key)}" found in collection. Every item in a collection must have a unique key.`
484 );
485 }
486 this.keyOwners.set(key, element);
487 }
488
489 let collection = this.getMutableCollection();
490 if (!collection.getItem(element.node.key)) {
491 for (let child of element) {
492 this.addNode(child);
493 }
494 }
495
496 collection.addNode(element.node);
497 }
498
499 private removeNode(node: ElementNode<T>): void {
500 for (let child of node) {

Callers 1

updateCollectionMethod · 0.95

Calls 4

getMutableCollectionMethod · 0.95
StringFunction · 0.85
getItemMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected