Home / Class/ ForkContext Class — react Architecture

ForkContext Class — react Architecture

Architecture documentation for the ForkContext class in fork-context.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  0daaee01_483b_d204_caa2_4c485a798e10["ForkContext"]
  07cca28a_69a9_0c86_6a6b_dd21af903a1e["fork-context.js"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|defined in| 07cca28a_69a9_0c86_6a6b_dd21af903a1e
  a101cff8_5498_6108_5f59_de00b5f022e2["constructor()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| a101cff8_5498_6108_5f59_de00b5f022e2
  3d44a120_1b05_f95e_90be_9f69cb915827["head()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| 3d44a120_1b05_f95e_90be_9f69cb915827
  11b78c9f_d123_2869_878d_d9d562f4ad54["empty()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| 11b78c9f_d123_2869_878d_d9d562f4ad54
  fb93ddb0_8414_15bd_7a35_d43b7889897e["reachable()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| fb93ddb0_8414_15bd_7a35_d43b7889897e
  01765794_411d_3be5_6b33_1dd7e7681105["makeNext()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| 01765794_411d_3be5_6b33_1dd7e7681105
  56a829db_3a55_2657_0a52_9fce196357a5["makeUnreachable()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| 56a829db_3a55_2657_0a52_9fce196357a5
  3cd1a843_6644_6341_ee01_b40866611a2f["makeDisconnected()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| 3cd1a843_6644_6341_ee01_b40866611a2f
  45f8c3bb_4c36_718d_e04b_0bbd066a1177["add()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| 45f8c3bb_4c36_718d_e04b_0bbd066a1177
  4cd7af73_2fb2_63dc_0b10_8600b5493d3c["replaceHead()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| 4cd7af73_2fb2_63dc_0b10_8600b5493d3c
  8ada2174_84f9_ba1c_eade_e0c0963d90d1["addAll()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| 8ada2174_84f9_ba1c_eade_e0c0963d90d1
  4ab5fe33_a9aa_b7bf_945b_f03897275d75["clear()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| 4ab5fe33_a9aa_b7bf_945b_f03897275d75
  97fb3132_205e_51ad_9c56_6a33be19a337["newRoot()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| 97fb3132_205e_51ad_9c56_6a33be19a337
  bd8ad662_b4b0_02fe_06f8_a02553e00589["newEmpty()"]
  0daaee01_483b_d204_caa2_4c485a798e10 -->|method| bd8ad662_b4b0_02fe_06f8_a02553e00589

Relationship Graph

Source Code

packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js lines 97–250

class ForkContext {
  /**
   * @param {IdGenerator} idGenerator An identifier generator for segments.
   * @param {ForkContext|null} upper An upper fork context.
   * @param {number} count A number of parallel segments.
   */
  constructor(idGenerator, upper, count) {
    this.idGenerator = idGenerator;
    this.upper = upper;
    this.count = count;
    this.segmentsList = [];
  }

  /**
   * The head segments.
   * @type {CodePathSegment[]}
   */
  get head() {
    const list = this.segmentsList;

    return list.length === 0 ? [] : list[list.length - 1];
  }

  /**
   * A flag which shows empty.
   * @type {boolean}
   */
  get empty() {
    return this.segmentsList.length === 0;
  }

  /**
   * A flag which shows reachable.
   * @type {boolean}
   */
  get reachable() {
    const segments = this.head;

    return segments.length > 0 && segments.some(isReachable);
  }

  /**
   * Creates new segments from this context.
   * @param {number} begin The first index of previous segments.
   * @param {number} end The last index of previous segments.
   * @returns {CodePathSegment[]} New segments.
   */
  makeNext(begin, end) {
    return makeSegments(this, begin, end, CodePathSegment.newNext);
  }

  /**
   * Creates new segments from this context.
   * The new segments is always unreachable.
   * @param {number} begin The first index of previous segments.
   * @param {number} end The last index of previous segments.
   * @returns {CodePathSegment[]} New segments.
   */
  makeUnreachable(begin, end) {
    return makeSegments(this, begin, end, CodePathSegment.newUnreachable);
  }

  /**
   * Creates new segments from this context.
   * The new segments don't have connections for previous segments.
   * But these inherit the reachable flag from this context.
   * @param {number} begin The first index of previous segments.
   * @param {number} end The last index of previous segments.
   * @returns {CodePathSegment[]} New segments.
   */
  makeDisconnected(begin, end) {
    return makeSegments(this, begin, end, CodePathSegment.newDisconnected);
  }

  /**
   * Adds segments into this context.
   * The added segments become the head.
   * @param {CodePathSegment[]} segments Segments to add.
   * @returns {void}
   */
  add(segments) {

Frequently Asked Questions

What is the ForkContext class?
ForkContext is a class in the react codebase, defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js.
Where is ForkContext defined?
ForkContext is defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js at line 97.

Analyze Your Own Codebase

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

Try Supermodel Free