Home / Function/ constructor() — vite Function Reference

constructor() — vite Function Reference

Architecture documentation for the constructor() function in hmr.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  99e78c4e_c5fd_cc5a_c78d_d4a1f68ab5ce["constructor()"]
  d86a8333_3c9a_922b_57b2_926575326289["HMRContext"]
  99e78c4e_c5fd_cc5a_c78d_d4a1f68ab5ce -->|defined in| d86a8333_3c9a_922b_57b2_926575326289
  807ccbf8_3770_7cc7_42ab_44a6fc97398b["constructor()"]
  807ccbf8_3770_7cc7_42ab_44a6fc97398b -->|calls| 99e78c4e_c5fd_cc5a_c78d_d4a1f68ab5ce
  807ccbf8_3770_7cc7_42ab_44a6fc97398b["constructor()"]
  99e78c4e_c5fd_cc5a_c78d_d4a1f68ab5ce -->|calls| 807ccbf8_3770_7cc7_42ab_44a6fc97398b
  style 99e78c4e_c5fd_cc5a_c78d_d4a1f68ab5ce fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/shared/hmr.ts lines 27–58

  constructor(
    private hmrClient: HMRClient,
    private ownerPath: string,
  ) {
    if (!hmrClient.dataMap.has(ownerPath)) {
      hmrClient.dataMap.set(ownerPath, {})
    }

    // when a file is hot updated, a new context is created
    // clear its stale callbacks
    const mod = hmrClient.hotModulesMap.get(ownerPath)
    if (mod) {
      mod.callbacks = []
    }

    // clear stale custom event listeners
    const staleListeners = hmrClient.ctxToListenersMap.get(ownerPath)
    if (staleListeners) {
      for (const [event, staleFns] of staleListeners) {
        const listeners = hmrClient.customListenersMap.get(event)
        if (listeners) {
          hmrClient.customListenersMap.set(
            event,
            listeners.filter((l) => !staleFns.includes(l)),
          )
        }
      }
    }

    this.newListeners = new Map()
    hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners)
  }

Domain

Subdomains

Called By

Frequently Asked Questions

What does constructor() do?
constructor() is a function in the vite codebase, defined in packages/vite/src/shared/hmr.ts.
Where is constructor() defined?
constructor() is defined in packages/vite/src/shared/hmr.ts at line 27.
What does constructor() call?
constructor() calls 1 function(s): constructor.
What calls constructor()?
constructor() is called by 1 function(s): constructor.

Analyze Your Own Codebase

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

Try Supermodel Free