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

Method addNode

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

Source from the content-addressed store, hash-verified

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