Home / File/ ReactCacheImpl.js — react Source File

ReactCacheImpl.js — react Source File

Architecture documentation for ReactCacheImpl.js, a javascript file in the react codebase. 1 imports, 1 dependents.

File javascript BabelCompiler 1 imports 1 dependents

Entity Profile

Dependency Diagram

graph LR
  a80e15dd_1ae3_bdaf_0881_b1db10f190ca["ReactCacheImpl.js"]
  1c5695a6_6806_ba54_2074_efc779e66da4["ReactSharedInternals"]
  a80e15dd_1ae3_bdaf_0881_b1db10f190ca --> 1c5695a6_6806_ba54_2074_efc779e66da4
  865f2152_61bc_2047_c4c5_db8102359517["ReactCacheClient.js"]
  865f2152_61bc_2047_c4c5_db8102359517 --> a80e15dd_1ae3_bdaf_0881_b1db10f190ca
  style a80e15dd_1ae3_bdaf_0881_b1db10f190ca fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and its 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 ReactSharedInternals from 'shared/ReactSharedInternals';

const UNTERMINATED = 0;
const TERMINATED = 1;
const ERRORED = 2;

type UnterminatedCacheNode<T> = {
  s: 0,
  v: void,
  o: null | WeakMap<Function | Object, CacheNode<T>>,
  p: null | Map<string | number | null | void | symbol | boolean, CacheNode<T>>,
};

type TerminatedCacheNode<T> = {
  s: 1,
  v: T,
  o: null | WeakMap<Function | Object, CacheNode<T>>,
  p: null | Map<string | number | null | void | symbol | boolean, CacheNode<T>>,
};

type ErroredCacheNode<T> = {
  s: 2,
  v: mixed,
  o: null | WeakMap<Function | Object, CacheNode<T>>,
  p: null | Map<string | number | null | void | symbol | boolean, CacheNode<T>>,
};

type CacheNode<T> =
  | TerminatedCacheNode<T>
  | UnterminatedCacheNode<T>
  | ErroredCacheNode<T>;

function createCacheRoot<T>(): WeakMap<Function | Object, CacheNode<T>> {
  return new WeakMap();
}

function createCacheNode<T>(): CacheNode<T> {
  return {
    s: UNTERMINATED, // status, represents whether the cached computation returned a value or threw an error
    v: undefined, // value, either the cached result or an error, depending on s
    o: null, // object cache, a WeakMap where non-primitive arguments are stored
    p: null, // primitive cache, a regular Map where primitive arguments are stored.
  };
}

export function cache<A: Iterable<mixed>, T>(fn: (...A) => T): (...A) => T {
  return function () {
    const dispatcher = ReactSharedInternals.A;
    if (!dispatcher) {
      // If there is no dispatcher, then we treat this as not being cached.
      // $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
// ... (81 more lines)

Domain

Dependencies

  • ReactSharedInternals

Frequently Asked Questions

What does ReactCacheImpl.js do?
ReactCacheImpl.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain.
What does ReactCacheImpl.js depend on?
ReactCacheImpl.js imports 1 module(s): ReactSharedInternals.
What files import ReactCacheImpl.js?
ReactCacheImpl.js is imported by 1 file(s): ReactCacheClient.js.
Where is ReactCacheImpl.js in the architecture?
ReactCacheImpl.js is located at packages/react/src/ReactCacheImpl.js (domain: BabelCompiler, directory: packages/react/src).

Analyze Your Own Codebase

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

Try Supermodel Free