attach() — react Function Reference
Architecture documentation for the attach() function in renderer.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 0bf1ec3e_7bcf_3a31_d050_f4e3bd960b04["attach()"] 27444ff2_8253_76db_da6c_4967b0d20cee["renderer.js"] 0bf1ec3e_7bcf_3a31_d050_f4e3bd960b04 -->|defined in| 27444ff2_8253_76db_da6c_4967b0d20cee 4aa16541_e301_4ecc_08b7_298b2c74473b["getData()"] 0bf1ec3e_7bcf_3a31_d050_f4e3bd960b04 -->|calls| 4aa16541_e301_4ecc_08b7_298b2c74473b 25f0e20e_3849_3b03_9630_fb8108361c04["decorateMany()"] 0bf1ec3e_7bcf_3a31_d050_f4e3bd960b04 -->|calls| 25f0e20e_3849_3b03_9630_fb8108361c04 cc77e32e_65f2_bb71_c3b3_89c3ff8f9852["getElementType()"] 0bf1ec3e_7bcf_3a31_d050_f4e3bd960b04 -->|calls| cc77e32e_65f2_bb71_c3b3_89c3ff8f9852 2f227955_4f5b_a05f_26dc_975311221f5d["getChildren()"] 0bf1ec3e_7bcf_3a31_d050_f4e3bd960b04 -->|calls| 2f227955_4f5b_a05f_26dc_975311221f5d f8c9cd72_bda8_fa8f_0cdf_9d602a414851["restoreMany()"] 0bf1ec3e_7bcf_3a31_d050_f4e3bd960b04 -->|calls| f8c9cd72_bda8_fa8f_0cdf_9d602a414851 8b4d3abb_904e_7034_555c_3d5d18aba7df["pushOperation()"] 0bf1ec3e_7bcf_3a31_d050_f4e3bd960b04 -->|calls| 8b4d3abb_904e_7034_555c_3d5d18aba7df style 0bf1ec3e_7bcf_3a31_d050_f4e3bd960b04 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-devtools-shared/src/backend/legacy/renderer.js lines 136–599
export function attach(
hook: DevToolsHook,
rendererID: number,
renderer: LegacyRenderer,
global: Object,
): RendererInterface {
const idToInternalInstanceMap: Map<number, InternalInstance> = new Map();
const internalInstanceToIDMap: WeakMap<InternalInstance, number> =
new WeakMap();
const internalInstanceToRootIDMap: WeakMap<InternalInstance, number> =
new WeakMap();
let getElementIDForHostInstance: GetElementIDForHostInstance =
((null: any): GetElementIDForHostInstance);
let findHostInstanceForInternalID: (id: number) => ?HostInstance;
let getNearestMountedDOMNode = (node: Element): null | Element => {
// Not implemented.
return null;
};
if (renderer.ComponentTree) {
getElementIDForHostInstance = node => {
const internalInstance =
renderer.ComponentTree.getClosestInstanceFromNode(node);
return internalInstanceToIDMap.get(internalInstance) || null;
};
findHostInstanceForInternalID = (id: number) => {
const internalInstance = idToInternalInstanceMap.get(id);
return renderer.ComponentTree.getNodeFromInstance(internalInstance);
};
getNearestMountedDOMNode = (node: Element): null | Element => {
const internalInstance =
renderer.ComponentTree.getClosestInstanceFromNode(node);
if (internalInstance != null) {
return renderer.ComponentTree.getNodeFromInstance(internalInstance);
}
return null;
};
} else if (renderer.Mount.getID && renderer.Mount.getNode) {
getElementIDForHostInstance = node => {
// Not implemented.
return null;
};
findHostInstanceForInternalID = (id: number) => {
// Not implemented.
return null;
};
}
const supportsTogglingSuspense = false;
function getDisplayNameForElementID(id: number): string | null {
const internalInstance = idToInternalInstanceMap.get(id);
return internalInstance ? getData(internalInstance).displayName : null;
}
function getID(internalInstance: InternalInstance): number {
if (typeof internalInstance !== 'object' || internalInstance === null) {
throw new Error('Invalid internal instance: ' + internalInstance);
}
if (!internalInstanceToIDMap.has(internalInstance)) {
const id = getUID();
internalInstanceToIDMap.set(internalInstance, id);
idToInternalInstanceMap.set(id, internalInstance);
}
return ((internalInstanceToIDMap.get(internalInstance): any): number);
}
function areEqualArrays(a: Array<any>, b: Array<any>) {
if (a.length !== b.length) {
return false;
}
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
}
// This is shared mutable state that lets us keep track of where we are.
Domain
Subdomains
Source
Frequently Asked Questions
What does attach() do?
attach() is a function in the react codebase, defined in packages/react-devtools-shared/src/backend/legacy/renderer.js.
Where is attach() defined?
attach() is defined in packages/react-devtools-shared/src/backend/legacy/renderer.js at line 136.
What does attach() call?
attach() calls 6 function(s): decorateMany, getChildren, getData, getElementType, pushOperation, restoreMany.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free