hook.js — react Source File
Architecture documentation for hook.js, a javascript file in the react codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR a49c4f66_71d5_8a62_f0a1_ffd7ca7bd5b2["hook.js"] 0304bbc8_f110_6643_71c6_d26bddc58fde["types.js"] a49c4f66_71d5_8a62_f0a1_ffd7ca7bd5b2 --> 0304bbc8_f110_6643_71c6_d26bddc58fde 501f1668_e338_41a4_686c_5b2aee4863b8["types.js"] a49c4f66_71d5_8a62_f0a1_ffd7ca7bd5b2 --> 501f1668_e338_41a4_686c_5b2aee4863b8 7d512385_b713_0511_a399_af3e878800fe["attachRenderer.js"] a49c4f66_71d5_8a62_f0a1_ffd7ca7bd5b2 --> 7d512385_b713_0511_a399_af3e878800fe 55d27179_f566_db64_927b_e95655abee00["constants"] a49c4f66_71d5_8a62_f0a1_ffd7ca7bd5b2 --> 55d27179_f566_db64_927b_e95655abee00 a4d341f3_6602_6975_dd35_25b8077b1c8c["formatConsoleArguments"] a49c4f66_71d5_8a62_f0a1_ffd7ca7bd5b2 --> a4d341f3_6602_6975_dd35_25b8077b1c8c 6249e5a0_2393_d4cf_0b30_3a369e5c2b27["formatWithStyles"] a49c4f66_71d5_8a62_f0a1_ffd7ca7bd5b2 --> 6249e5a0_2393_d4cf_0b30_3a369e5c2b27 style a49c4f66_71d5_8a62_f0a1_ffd7ca7bd5b2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Install the hook on window, which is an event emitter.
* Note: this global hook __REACT_DEVTOOLS_GLOBAL_HOOK__ is a de facto public API.
* It's especially important to avoid creating direct dependency on the DevTools Backend.
* That's why we still inline the whole event emitter implementation,
* the string format implementation, and part of the console implementation here.
*
* @flow
*/
import type {
DevToolsHook,
Handler,
ReactRenderer,
RendererID,
RendererInterface,
DevToolsBackend,
DevToolsHookSettings,
ProfilingSettings,
} from './backend/types';
import type {ComponentFilter} from './frontend/types';
import {
FIREFOX_CONSOLE_DIMMING_COLOR,
ANSI_STYLE_DIMMING_TEMPLATE,
ANSI_STYLE_DIMMING_TEMPLATE_WITH_COMPONENT_STACK,
} from 'react-devtools-shared/src/constants';
import attachRenderer from './attachRenderer';
import formatConsoleArguments from 'react-devtools-shared/src/backend/utils/formatConsoleArguments';
import formatWithStyles from 'react-devtools-shared/src/backend/utils/formatWithStyles';
// React's custom built component stack strings match "\s{4}in"
// Chrome's prefix matches "\s{4}at"
const PREFIX_REGEX = /\s{4}(in|at)\s{1}/;
// Firefox and Safari have no prefix ("")
// but we can fallback to looking for location info (e.g. "foo.js:12:345")
const ROW_COLUMN_NUMBER_REGEX = /:\d+:\d+(\n|$)/;
function isStringComponentStack(text: string): boolean {
return PREFIX_REGEX.test(text) || ROW_COLUMN_NUMBER_REGEX.test(text);
}
// We add a suffix to some frames that older versions of React didn't do.
// To compare if it's equivalent we strip out the suffix to see if they're
// still equivalent. Similarly, we sometimes use [] and sometimes () so we
// strip them to for the comparison.
const frameDiffs = / \(\<anonymous\>\)$|\@unknown\:0\:0$|\(|\)|\[|\]/gm;
function areStackTracesEqual(a: string, b: string): boolean {
return a.replace(frameDiffs, '') === b.replace(frameDiffs, '');
}
const targetConsole: Object = console;
const defaultProfilingSettings: ProfilingSettings = {
recordChangeDescriptions: false,
recordTimeline: false,
};
export function installHook(
target: any,
// ... (657 more lines)
Domain
Dependencies
- attachRenderer.js
- constants
- formatConsoleArguments
- formatWithStyles
- types.js
- types.js
Source
Frequently Asked Questions
What does hook.js do?
hook.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain.
What does hook.js depend on?
hook.js imports 6 module(s): attachRenderer.js, constants, formatConsoleArguments, formatWithStyles, types.js, types.js.
Where is hook.js in the architecture?
hook.js is located at packages/react-devtools-shared/src/hook.js (domain: BabelCompiler, directory: packages/react-devtools-shared/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free