Home / Function/ initBackend() — react Function Reference

initBackend() — react Function Reference

Architecture documentation for the initBackend() function in index.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  aefb7752_38da_b529_ee9a_c94b8d2afcbe["initBackend()"]
  7fba5194_4415_41ad_1366_ead346337fb8["index.js"]
  aefb7752_38da_b529_ee9a_c94b8d2afcbe -->|defined in| 7fba5194_4415_41ad_1366_ead346337fb8
  style aefb7752_38da_b529_ee9a_c94b8d2afcbe fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-devtools-shared/src/backend/index.js lines 16–102

export function initBackend(
  hook: DevToolsHook,
  agent: Agent,
  global: Object,
  isReloadAndProfileSupported: boolean,
): () => void {
  if (hook == null) {
    // DevTools didn't get injected into this page (maybe b'c of the contentType).
    return () => {};
  }

  function registerRendererInterface(
    id: RendererID,
    rendererInterface: RendererInterface,
  ) {
    agent.registerRendererInterface(id, rendererInterface);

    // Now that the Store and the renderer interface are connected,
    // it's time to flush the pending operation codes to the frontend.
    rendererInterface.flushInitialOperations();
  }

  const subs = [
    hook.sub(
      'renderer-attached',
      ({
        id,
        rendererInterface,
      }: {
        id: number,
        rendererInterface: RendererInterface,
      }) => {
        registerRendererInterface(id, rendererInterface);
      },
    ),
    hook.sub('unsupported-renderer-version', () => {
      agent.onUnsupportedRenderer();
    }),

    hook.sub('fastRefreshScheduled', agent.onFastRefreshScheduled),
    hook.sub('operations', agent.onHookOperations),
    hook.sub('traceUpdates', agent.onTraceUpdates),
    hook.sub('settingsInitialized', agent.onHookSettings),

    // TODO Add additional subscriptions required for profiling mode
  ];

  agent.addListener('getIfHasUnsupportedRendererVersion', () => {
    if (hook.hasUnsupportedRendererAttached) {
      agent.onUnsupportedRenderer();
    }
  });

  hook.rendererInterfaces.forEach((rendererInterface, id) => {
    registerRendererInterface(id, rendererInterface);
  });

  hook.emit('react-devtools', agent);
  hook.reactDevtoolsAgent = agent;

  const onAgentShutdown = () => {
    subs.forEach(fn => fn());
    hook.rendererInterfaces.forEach(rendererInterface => {
      rendererInterface.cleanup();
    });
    hook.reactDevtoolsAgent = null;
  };

  // Agent's event listeners are cleaned up by Agent in `shutdown` implementation.
  agent.addListener('shutdown', onAgentShutdown);
  agent.addListener('updateHookSettings', settings => {
    hook.settings = settings;
  });
  agent.addListener('getHookSettings', () => {
    if (hook.settings != null) {
      agent.onHookSettings(hook.settings);
    }
  });

  if (isReloadAndProfileSupported) {
    agent.onReloadAndProfileSupportedByHost();

Domain

Subdomains

Frequently Asked Questions

What does initBackend() do?
initBackend() is a function in the react codebase, defined in packages/react-devtools-shared/src/backend/index.js.
Where is initBackend() defined?
initBackend() is defined in packages/react-devtools-shared/src/backend/index.js at line 16.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free