Home / File/ backend.js — react Source File

backend.js — react Source File

Architecture documentation for backend.js, a javascript file in the react codebase. 7 imports, 0 dependents.

File javascript BabelCompiler Validation 7 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  354fe138_8fc9_c8a1_a2a8_b5eba888a4c5["backend.js"]
  7812cbae_0bd0_497c_0a05_31fe0a8d0fde["agent"]
  354fe138_8fc9_c8a1_a2a8_b5eba888a4c5 --> 7812cbae_0bd0_497c_0a05_31fe0a8d0fde
  4077b620_5c59_61c2_0910_273f565da757["bridge"]
  354fe138_8fc9_c8a1_a2a8_b5eba888a4c5 --> 4077b620_5c59_61c2_0910_273f565da757
  bb23732c_ecb9_fba3_cd32_68ff2320751d["backend"]
  354fe138_8fc9_c8a1_a2a8_b5eba888a4c5 --> bb23732c_ecb9_fba3_cd32_68ff2320751d
  bdc0f51e_4952_e5a8_d3d8_502a65e31437["hook"]
  354fe138_8fc9_c8a1_a2a8_b5eba888a4c5 --> bdc0f51e_4952_e5a8_d3d8_502a65e31437
  a0f3dac9_e573_4923_3098_4bb9e10f0e2d["setupNativeStyleEditor"]
  354fe138_8fc9_c8a1_a2a8_b5eba888a4c5 --> a0f3dac9_e573_4923_3098_4bb9e10f0e2d
  aec7978f_0a19_ba93_de9e_ac8cf5ddc74b["types"]
  354fe138_8fc9_c8a1_a2a8_b5eba888a4c5 --> aec7978f_0a19_ba93_de9e_ac8cf5ddc74b
  627bb742_21aa_b4fd_fe2d_4a963a1f9278["utils"]
  354fe138_8fc9_c8a1_a2a8_b5eba888a4c5 --> 627bb742_21aa_b4fd_fe2d_4a963a1f9278
  style 354fe138_8fc9_c8a1_a2a8_b5eba888a4c5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @flow */

import Agent from 'react-devtools-shared/src/backend/agent';
import Bridge from 'react-devtools-shared/src/bridge';
import {initBackend} from 'react-devtools-shared/src/backend';
import {installHook} from 'react-devtools-shared/src/hook';
import setupNativeStyleEditor from 'react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor';

import type {
  BackendBridge,
  SavedPreferencesParams,
} from 'react-devtools-shared/src/bridge';
import type {
  ComponentFilter,
  Wall,
} from 'react-devtools-shared/src/frontend/types';
import {
  getIfReloadedAndProfiling,
  getIsReloadAndProfileSupported,
  onReloadAndProfile,
  onReloadAndProfileFlagsReset,
} from 'react-devtools-shared/src/utils';

let resolveComponentFiltersInjection: (filters: Array<ComponentFilter>) => void;
const componentFiltersPromise = new Promise<Array<ComponentFilter>>(resolve => {
  resolveComponentFiltersInjection = resolve;
});

function startActivation(contentWindow: any, bridge: BackendBridge) {
  const onSavedPreferences = (data: SavedPreferencesParams) => {
    // This is the only message we're listening for,
    // so it's safe to cleanup after we've received it.
    bridge.removeListener('savedPreferences', onSavedPreferences);

    const {componentFilters} = data;

    resolveComponentFiltersInjection(componentFilters);
  };

  componentFiltersPromise.then(
    finishActivation.bind(null, contentWindow, bridge),
  );

  bridge.addListener('savedPreferences', onSavedPreferences);

  // The backend may be unable to read saved preferences directly,
  // because they are stored in localStorage within the context of the extension (on the frontend).
  // Instead it relies on the extension to pass preferences through.
  // Because we might be in a sandboxed iframe, we have to ask for them by way of postMessage().
  bridge.send('getSavedPreferences');
}

function finishActivation(contentWindow: any, bridge: BackendBridge) {
  const agent = new Agent(
    bridge,
    getIfReloadedAndProfiling(),
    onReloadAndProfile,
  );
  onReloadAndProfileFlagsReset();

  const hook = contentWindow.__REACT_DEVTOOLS_GLOBAL_HOOK__;
  if (hook) {
    initBackend(hook, agent, contentWindow, getIsReloadAndProfileSupported());

    // Setup React Native style editor if a renderer like react-native-web has injected it.
    if (hook.resolveRNStyle) {
      setupNativeStyleEditor(
        bridge,
        agent,
        hook.resolveRNStyle,
        hook.nativeStyleEditorValidAttributes,
      );
    }
  }
}

export function activate(
  contentWindow: any,
  {
    bridge,
  }: {
    bridge?: BackendBridge,
  } = {},
): void {
  if (bridge == null) {
    bridge = createBridge(contentWindow);
  }

  startActivation(contentWindow, bridge);
}

export function createBridge(contentWindow: any, wall?: Wall): BackendBridge {
  const {parent} = contentWindow;

  if (wall == null) {
    wall = {
      listen(fn) {
        const onMessage = ({data}: $FlowFixMe) => {
          fn(data);
        };
        contentWindow.addEventListener('message', onMessage);
        return () => {
          contentWindow.removeEventListener('message', onMessage);
        };
      },
      send(event: string, payload: any, transferable?: Array<any>) {
        parent.postMessage({event, payload}, '*', transferable);
      },
    };
  }

  return (new Bridge(wall): BackendBridge);
}

export function initialize(contentWindow: any): void {
  installHook(contentWindow, componentFiltersPromise);
}

Domain

Subdomains

Dependencies

  • agent
  • backend
  • bridge
  • hook
  • setupNativeStyleEditor
  • types
  • utils

Frequently Asked Questions

What does backend.js do?
backend.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in backend.js?
backend.js defines 4 function(s): activate, componentFiltersPromise, finishActivation, startActivation.
What does backend.js depend on?
backend.js imports 7 module(s): agent, backend, bridge, hook, setupNativeStyleEditor, types, utils.
Where is backend.js in the architecture?
backend.js is located at packages/react-devtools-inline/src/backend.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-inline/src).

Analyze Your Own Codebase

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

Try Supermodel Free