MCPcopy
hub / github.com/facebook/react / initBackend

Function initBackend

packages/react-devtools-shared/src/backend/index.js:16–102  ·  view source on GitHub ↗
(
  hook: DevToolsHook,
  agent: Agent,
  global: Object,
  isReloadAndProfileSupported: boolean,
)

Source from the content-addressed store, hash-verified

14export type InitBackend = typeof initBackend;
15
16export function initBackend(
17 hook: DevToolsHook,
18 agent: Agent,
19 global: Object,
20 isReloadAndProfileSupported: boolean,
21): () => void {
22 if (hook == null) {
23 // DevTools didn't get injected into this page (maybe b'c of the contentType).
24 return () => {};
25 }
26
27 function registerRendererInterface(
28 id: RendererID,
29 rendererInterface: RendererInterface,
30 ) {
31 agent.registerRendererInterface(id, rendererInterface);
32
33 // Now that the Store and the renderer interface are connected,
34 // it's time to flush the pending operation codes to the frontend.
35 rendererInterface.flushInitialOperations();
36 }
37
38 const subs = [
39 hook.sub(
40 'renderer-attached',
41 ({
42 id,
43 rendererInterface,
44 }: {
45 id: number,
46 rendererInterface: RendererInterface,
47 }) => {
48 registerRendererInterface(id, rendererInterface);
49 },
50 ),
51 hook.sub('unsupported-renderer-version', () => {
52 agent.onUnsupportedRenderer();
53 }),
54
55 hook.sub('fastRefreshScheduled', agent.onFastRefreshScheduled),
56 hook.sub('operations', agent.onHookOperations),
57 hook.sub('traceUpdates', agent.onTraceUpdates),
58 hook.sub('settingsInitialized', agent.onHookSettings),
59
60 // TODO Add additional subscriptions required for profiling mode
61 ];
62
63 agent.addListener('getIfHasUnsupportedRendererVersion', () => {
64 if (hook.hasUnsupportedRendererAttached) {
65 agent.onUnsupportedRenderer();
66 }
67 });
68
69 hook.rendererInterfaces.forEach((rendererInterface, id) => {
70 registerRendererInterface(id, rendererInterface);
71 });
72
73 hook.emit('react-devtools', agent);

Callers 5

finishActivationFunction · 0.90
connectToDevToolsFunction · 0.90
setupTests.jsFile · 0.85
activateBackendFunction · 0.85

Calls 6

onUnsupportedRendererMethod · 0.80
addListenerMethod · 0.65
forEachMethod · 0.65
fnFunction · 0.50
emitMethod · 0.45

Tested by

no test coverage detected