union() — react Function Reference
Architecture documentation for the union() function in DisjointSet.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD a89a21a8_52fd_f4df_8805_31b9e3fb228e["union()"] 1765a682_3028_4441_b26f_c712ca2597d5["DisjointSet"] a89a21a8_52fd_f4df_8805_31b9e3fb228e -->|defined in| 1765a682_3028_4441_b26f_c712ca2597d5 74efde51_a311_d84c_0e23_ddafd072e338["find()"] a89a21a8_52fd_f4df_8805_31b9e3fb228e -->|calls| 74efde51_a311_d84c_0e23_ddafd072e338 041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"] a89a21a8_52fd_f4df_8805_31b9e3fb228e -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e style a89a21a8_52fd_f4df_8805_31b9e3fb228e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Utils/DisjointSet.ts lines 20–54
union(items: Array<T>): void {
const first = items.shift();
CompilerError.invariant(first != null, {
reason: 'Expected set to be non-empty',
loc: GeneratedSource,
});
/*
* determine an arbitrary "root" for this set: if the first
* item already has a root then use that, otherwise the first item
* will be the new root.
*/
let root = this.find(first);
if (root == null) {
root = first;
this.#entries.set(first, first);
}
// update remaining items (which may already be part of other sets)
for (const item of items) {
let itemParent = this.#entries.get(item);
if (itemParent == null) {
// new item, no existing set to update
this.#entries.set(item, root);
continue;
} else if (itemParent === root) {
continue;
} else {
let current = item;
while (itemParent !== root) {
this.#entries.set(current, root);
current = itemParent;
itemParent = this.#entries.get(current)!;
}
}
}
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does union() do?
union() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Utils/DisjointSet.ts.
Where is union() defined?
union() is defined in compiler/packages/babel-plugin-react-compiler/src/Utils/DisjointSet.ts at line 20.
What does union() call?
union() calls 2 function(s): find, invariant.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free