Home / File/ utils.js — react Source File

utils.js — react Source File

Architecture documentation for utils.js, a javascript file in the react codebase. 5 imports, 4 dependents.

File javascript BabelCompiler Validation 5 imports 4 dependents 7 functions

Entity Profile

Dependency Diagram

graph LR
  fa31bba5_57ed_1039_52bb_4a8cb4382642["utils.js"]
  2d59b0f9_9ad6_da4d_0264_d98f193ab3fd["TreeContext.js"]
  fa31bba5_57ed_1039_52bb_4a8cb4382642 --> 2d59b0f9_9ad6_da4d_0264_d98f193ab3fd
  bba85af0_a356_d0c5_4d12_914508b89593["store.js"]
  fa31bba5_57ed_1039_52bb_4a8cb4382642 --> bba85af0_a356_d0c5_4d12_914508b89593
  0caa962b_0696_d71a_4cb9_f018bdf9def1["json5"]
  fa31bba5_57ed_1039_52bb_4a8cb4382642 --> 0caa962b_0696_d71a_4cb9_f018bdf9def1
  d8f20c67_f5fa_0f0a_c967_c41fd9ffce07["ReactTypes"]
  fa31bba5_57ed_1039_52bb_4a8cb4382642 --> d8f20c67_f5fa_0f0a_c967_c41fd9ffce07
  aec7978f_0a19_ba93_de9e_ac8cf5ddc74b["types"]
  fa31bba5_57ed_1039_52bb_4a8cb4382642 --> aec7978f_0a19_ba93_de9e_ac8cf5ddc74b
  bba85af0_a356_d0c5_4d12_914508b89593["store.js"]
  bba85af0_a356_d0c5_4d12_914508b89593 --> fa31bba5_57ed_1039_52bb_4a8cb4382642
  a7173e0c_ba07_009a_1ada_f864062596b5["StyleEditor.js"]
  a7173e0c_ba07_009a_1ada_f864062596b5 --> fa31bba5_57ed_1039_52bb_4a8cb4382642
  bb770434_43dc_71aa_77ec_098236a83413["NewArrayValue.js"]
  bb770434_43dc_71aa_77ec_098236a83413 --> fa31bba5_57ed_1039_52bb_4a8cb4382642
  315baf50_1028_51ca_a9c1_679c6a17ed98["hooks.js"]
  315baf50_1028_51ca_a9c1_679c6a17ed98 --> fa31bba5_57ed_1039_52bb_4a8cb4382642
  style fa31bba5_57ed_1039_52bb_4a8cb4382642 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

import JSON5 from 'json5';

import type {ReactFunctionLocation} from 'shared/ReactTypes';
import type {
  Element,
  SuspenseNode,
} from 'react-devtools-shared/src/frontend/types';
import type {StateContext} from './views/Components/TreeContext';
import type Store from './store';

export function printElement(
  element: Element,
  includeWeight: boolean = false,
): string {
  let prefix = ' ';
  if (element.children.length > 0) {
    prefix = element.isCollapsed ? '▸' : '▾';
  }

  let key = '';
  if (element.key !== null) {
    key = ` key="${element.key}"`;
  }

  let name = '';
  if (element.nameProp !== null) {
    name = ` name="${element.nameProp}"`;
  }

  let hocDisplayNames = null;
  if (element.hocDisplayNames !== null) {
    hocDisplayNames = [...element.hocDisplayNames];
  }

  const hocs =
    hocDisplayNames === null ? '' : ` [${hocDisplayNames.join('][')}]`;

  let suffix = '';
  if (includeWeight) {
    suffix = ` (${element.isCollapsed ? 1 : element.weight})`;
  }

  return `${'  '.repeat(element.depth + 1)}${prefix} <${
    element.displayName || 'null'
  }${key}${name}>${hocs}${suffix}`;
}

function printRects(rects: SuspenseNode['rects']): string {
  if (rects === null) {
    return ' rects={null}';
  } else {
// ... (219 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does utils.js do?
utils.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 utils.js?
utils.js defines 7 function(s): printElement, printOwnersList, printRects, printStore, printSuspense, printSuspenseWithChildren, smartStringify.
What does utils.js depend on?
utils.js imports 5 module(s): ReactTypes, TreeContext.js, json5, store.js, types.
What files import utils.js?
utils.js is imported by 4 file(s): NewArrayValue.js, StyleEditor.js, hooks.js, store.js.
Where is utils.js in the architecture?
utils.js is located at packages/react-devtools-shared/src/devtools/utils.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/devtools).

Analyze Your Own Codebase

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

Try Supermodel Free