MCPcopy
hub / github.com/vitejs/vite / constructor

Method constructor

packages/vite/src/shared/hmr.ts:27–58  ·  view source on GitHub ↗
(
    private hmrClient: HMRClient,
    private ownerPath: string,
  )

Source from the content-addressed store, hash-verified

25 private newListeners: CustomListenersMap
26
27 constructor(
28 private hmrClient: HMRClient,
29 private ownerPath: string,
30 ) {
31 if (!hmrClient.dataMap.has(ownerPath)) {
32 hmrClient.dataMap.set(ownerPath, {})
33 }
34
35 // when a file is hot updated, a new context is created
36 // clear its stale callbacks
37 const mod = hmrClient.hotModulesMap.get(ownerPath)
38 if (mod) {
39 mod.callbacks = []
40 }
41
42 // clear stale custom event listeners
43 const staleListeners = hmrClient.ctxToListenersMap.get(ownerPath)
44 if (staleListeners) {
45 for (const [event, staleFns] of staleListeners) {
46 const listeners = hmrClient.customListenersMap.get(event)
47 if (listeners) {
48 hmrClient.customListenersMap.set(
49 event,
50 listeners.filter((l) => !staleFns.includes(l)),
51 )
52 }
53 }
54 }
55
56 this.newListeners = new Map()
57 hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners)
58 }
59
60 get data(): any {
61 return this.hmrClient.dataMap.get(this.ownerPath)

Callers

nothing calls this directly

Calls 3

hasMethod · 0.80
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected