Home / Class/ ReactivityMap Class — react Architecture

ReactivityMap Class — react Architecture

Architecture documentation for the ReactivityMap class in InferReactivePlaces.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  709db791_cb84_4ab6_9847_e4749adb938f["ReactivityMap"]
  725143dd_a713_5e8e_fdf0_9c99de3b528f["InferReactivePlaces.ts"]
  709db791_cb84_4ab6_9847_e4749adb938f -->|defined in| 725143dd_a713_5e8e_fdf0_9c99de3b528f
  7812b438_3bea_9ead_e14a_82767db88ab1["constructor()"]
  709db791_cb84_4ab6_9847_e4749adb938f -->|method| 7812b438_3bea_9ead_e14a_82767db88ab1
  35406eee_9521_0419_7a1e_5d1f16da6f89["isReactive()"]
  709db791_cb84_4ab6_9847_e4749adb938f -->|method| 35406eee_9521_0419_7a1e_5d1f16da6f89
  a9512b67_abe2_2599_90d7_8e0d1c81a618["markReactive()"]
  709db791_cb84_4ab6_9847_e4749adb938f -->|method| a9512b67_abe2_2599_90d7_8e0d1c81a618
  e2b6f209_e0ee_d067_5cde_f180db8dbb52["snapshot()"]
  709db791_cb84_4ab6_9847_e4749adb938f -->|method| e2b6f209_e0ee_d067_5cde_f180db8dbb52

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Inference/InferReactivePlaces.ts lines 368–413

class ReactivityMap {
  hasChanges: boolean = false;
  reactive: Set<IdentifierId> = new Set();

  /**
   * Sets of mutably aliased identifiers — these are the same foundation for determining
   * reactive scopes a few passes later. The actual InferReactiveScopeVariables pass runs
   * after LeaveSSA, which artificially merges mutable ranges in cases such as declarations
   * that are later reassigned. Here we use only the underlying sets of mutably aliased values.
   *
   * Any identifier that has a mapping in this disjoint set will be treated as a stand in for
   * its canonical identifier in all cases, so that any reactivity flowing into one identifier of
   * an alias group will effectively make the whole alias group (all its identifiers) reactive.
   */
  aliasedIdentifiers: DisjointSet<Identifier>;

  constructor(aliasedIdentifiers: DisjointSet<Identifier>) {
    this.aliasedIdentifiers = aliasedIdentifiers;
  }

  isReactive(place: Place): boolean {
    const identifier =
      this.aliasedIdentifiers.find(place.identifier) ?? place.identifier;
    const reactive = this.reactive.has(identifier.id);
    if (reactive) {
      place.reactive = true;
    }
    return reactive;
  }

  markReactive(place: Place): void {
    place.reactive = true;
    const identifier =
      this.aliasedIdentifiers.find(place.identifier) ?? place.identifier;
    if (!this.reactive.has(identifier.id)) {
      this.hasChanges = true;
      this.reactive.add(identifier.id);
    }
  }

  snapshot(): boolean {
    const hasChanges = this.hasChanges;
    this.hasChanges = false;
    return hasChanges;
  }
}

Domain

Frequently Asked Questions

What is the ReactivityMap class?
ReactivityMap is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferReactivePlaces.ts.
Where is ReactivityMap defined?
ReactivityMap is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferReactivePlaces.ts at line 368.

Analyze Your Own Codebase

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

Try Supermodel Free