mirror of
https://github.com/JasonYANG170/IOTConnect-Web.git
synced 2024-11-27 14:16:34 +00:00
1 line
52 KiB
Plaintext
1 line
52 KiB
Plaintext
|
{"version":3,"file":"client.mjs","sources":["hmr.ts","overlay.ts","client.ts"],"sourcesContent":["import type { Update } from 'types/hmrPayload'\nimport type { ModuleNamespace, ViteHotContext } from 'types/hot'\nimport type { InferCustomEventPayload } from 'types/customEvent'\n\ntype CustomListenersMap = Map<string, ((data: any) => void)[]>\n\ninterface HotModule {\n id: string\n callbacks: HotCallback[]\n}\n\ninterface HotCallback {\n // the dependencies must be fetchable paths\n deps: string[]\n fn: (modules: Array<ModuleNamespace | undefined>) => void\n}\n\nexport interface HMRLogger {\n error(msg: string | Error): void\n debug(...msg: unknown[]): void\n}\n\nexport interface HMRConnection {\n /**\n * Checked before sending messages to the client.\n */\n isReady(): boolean\n /**\n * Send message to the client.\n */\n send(messages: string): void\n}\n\nexport class HMRContext implements ViteHotContext {\n private newListeners: CustomListenersMap\n\n constructor(\n private hmrClient: HMRClient,\n private ownerPath: string,\n ) {\n if (!hmrClient.dataMap.has(ownerPath)) {\n hmrClient.dataMap.set(ownerPath, {})\n }\n\n // when a file is hot updated, a new context is created\n // clear its stale callbacks\n const mod = hmrClient.hotModulesMap.get(ownerPath)\n if (mod) {\n mod.callbacks = []\n }\n\n // clear stale custom event listeners\n const staleListeners = hmrClient.ctxToListenersMap.get(ownerPath)\n if (staleListeners) {\n for (const [event, staleFns] of staleListeners) {\n const listeners = hmrClient.customListenersMap.get(event)\n if (listeners) {\n hmrClient.customListenersMap.set(\n event,\n listeners.filter((l) => !staleFns.includes(l)),\n )\n }\n }\n }\n\n this.newListeners = new Map()\n hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners)\n }\n\n get data(): any {\n return this.hmrClient.dataMap.get(this.ownerPath)\n }\n\n accept(deps?: any, callback?: any): void {\n if (typeof deps === 'function' || !deps) {\n // self-accept: hot.accept(() => {})\n this.acceptDeps([this.ownerPath], ([mod]) => deps?.(mod))\n } else if (typeof deps === 'string') {\n // explicit deps\n this.acceptDeps([deps], ([mod]) => callback?.(mod))\n } else if (Array.isArray(deps)) {\n this.acceptDeps(deps, callback)\n } else {\n throw new Error(`invalid hot.accept() usage.`)\n }\n }\n\n // export names (first arg) are irrelevant on the client side, they're\n // extracted in the server for propagation\n acceptExports(\n _: string | readonly string[],\n callback: (data: any) => void,\n ): void {\n this.acceptDeps([this.ownerPath], ([mod]) => callback?.(mod))\n }\n\n dispose(cb: (data: any) => void): void {\n this.hmrClient.disposeMap.set(this.ownerPath, cb)\n }\n\n prune(cb: (data: any) => void): void {\n this.hmrClient.pruneMap.set(this.ownerPath, cb)\n }\n\n // Kept for backward compatibility (#11036)\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n decline(): void {}\n\n invalidate(message: string): void {\n this.hmrClient.notifyListeners('vite:invalidate', {\n path: this.ownerPath,\n message,\n })\n this.send('vite:invalidate', { path: this.ownerPath, message })\n this.hmrClient.logger.debug(\n `[vite] invalidate ${this.ownerPath}${message ? `: ${message}` : ''}`,\n )\n }\n\n on<T extends string>(\n event: T,\n cb: (payload: InferCustomEventPayload<T>) => void,\n ): void {\n const addToMap = (map: Map<string, any[]>) => {\n const existing = map.get(event) || []\n existing.push(cb)\n map.set(event, existing)\n }\n addToMap(this.hmrClient.customListenersMap)\n addToMap(this.newListeners)\n }\n\n off<T extends string>(\n event: T,\n cb: (payload: InferCustomEventPayload<T>) => void,\n ): void {\n const removeFromMap = (map: Map<string, any[]>) => {\n const existing = map.get(event)\n if (existing === u
|