ember-vite-hmr 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Route from '@ember/routing/route';
|
|
2
|
+
import Service from '@ember/service';
|
|
2
3
|
import Component from '@glimmer/component';
|
|
3
4
|
import { getInternalComponentManager } from '@glimmer/manager';
|
|
4
5
|
|
|
@@ -18,7 +19,7 @@ function getState(component, skip) {
|
|
|
18
19
|
for (const key in component) {
|
|
19
20
|
if (skip.includes(key)) continue;
|
|
20
21
|
const entry = findPropertyDescriptor(component, key);
|
|
21
|
-
if (entry) {
|
|
22
|
+
if (entry && !(component[key] instanceof Service)) {
|
|
22
23
|
if (entry.writable && !Object.prototype.toString.call(entry.value).includes('Function')) {
|
|
23
24
|
state[key] = component[key];
|
|
24
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-hmr-manager.js","sources":["../../src/instance-initializers/setup-hmr-manager.ts"],"sourcesContent":["import Route from '@ember/routing/route';\nimport Controller from '@ember/controller';\nimport Component from '@glimmer/component';\n// @ts-ignore\nimport { getInternalComponentManager } from '@glimmer/manager';\n\ninterface HotComponent extends Component<{ __hot__?: any }> {\n __get_hot_state__?: () => Record<string, any>;\n}\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: any;\n};\n\nfunction findPropertyDescriptor(component: Object, key: string) {\n let proto = component;\n while (proto) {\n const desc = Object.getOwnPropertyDescriptor(proto, key);\n if (desc) return desc;\n proto = Object.getPrototypeOf(proto);\n }\n}\n\nfunction getState(component: HotComponent, skip: string[]) {\n const state: Record<string, any> = {};\n if (!component) {\n return state;\n }\n for (const key in component) {\n if (skip.includes(key)) continue;\n const entry = findPropertyDescriptor(component, key);\n if (entry) {\n if (\n entry.writable &&\n !Object.prototype.toString.call(entry.value).includes('Function')\n ) {\n state[key] = component[key as keyof Component];\n }\n if (entry.set) {\n state[key] = component[key as keyof Component];\n }\n }\n }\n return state;\n}\n\nfunction syncState(instance: Mutable<HotComponent>) {\n if (instance.args.__hot__) {\n const state =\n instance.__get_hot_state__?.() || instance.args.__hot__.getState?.();\n for (const k in state) {\n instance[k as keyof HotComponent] = state[k];\n }\n instance.args.__hot__.getState = () => getState(instance, ['args']);\n }\n}\n\nexport function initialize() {\n const ComponentManager = getInternalComponentManager(Component);\n const proto = Object.getPrototypeOf(ComponentManager);\n const create = proto.create;\n proto.create = function (...args: any[]) {\n const instance = create.call(this, ...args);\n syncState(instance.component);\n return instance;\n };\n\n const setupController = Route.prototype.setupController;\n\n const StateCache: Record<string, any> = {};\n\n Route.prototype.setupController = function (...args: any[]) {\n const controller = args[0];\n // @ts-ignore\n const r = setupController.call(this, ...args);\n const fullRouteName = this.fullRouteName;\n const state = StateCache[fullRouteName] || {};\n const skip = ['_qpDelegate', 'target', 'queryParams'];\n const routerState = getState(state.router, skip);\n const controllerState = getState(state.controller, skip);\n for (const k in routerState) {\n (this as any)[k] = routerState[k];\n }\n for (const k in controllerState) {\n controller[k] = controllerState[k];\n }\n StateCache[fullRouteName] = {\n route: this,\n controller,\n };\n return r;\n };\n}\n\nexport default {\n initialize,\n};\n"],"names":["findPropertyDescriptor","component","key","proto","desc","Object","getOwnPropertyDescriptor","getPrototypeOf","getState","skip","state","includes","entry","writable","prototype","toString","call","value","set","syncState","instance","args","__hot__","__get_hot_state__","k","initialize","ComponentManager","getInternalComponentManager","Component","create","setupController","Route","StateCache","controller","r","fullRouteName","routerState","router","controllerState","route"],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup-hmr-manager.js","sources":["../../src/instance-initializers/setup-hmr-manager.ts"],"sourcesContent":["import Route from '@ember/routing/route';\nimport Controller from '@ember/controller';\nimport Service from '@ember/service';\nimport Component from '@glimmer/component';\n// @ts-ignore\nimport { getInternalComponentManager } from '@glimmer/manager';\n\ninterface HotComponent extends Component<{ __hot__?: any }> {\n __get_hot_state__?: () => Record<string, any>;\n}\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: any;\n};\n\nfunction findPropertyDescriptor(component: Object, key: string) {\n let proto = component;\n while (proto) {\n const desc = Object.getOwnPropertyDescriptor(proto, key);\n if (desc) return desc;\n proto = Object.getPrototypeOf(proto);\n }\n}\n\nfunction getState(component: HotComponent, skip: string[]) {\n const state: Record<string, any> = {};\n if (!component) {\n return state;\n }\n for (const key in component) {\n if (skip.includes(key)) continue;\n const entry = findPropertyDescriptor(component, key);\n if (entry && !(component[key as keyof Component] instanceof Service)) {\n if (\n entry.writable &&\n !Object.prototype.toString.call(entry.value).includes('Function')\n ) {\n state[key] = component[key as keyof Component];\n }\n if (entry.set) {\n state[key] = component[key as keyof Component];\n }\n }\n }\n return state;\n}\n\nfunction syncState(instance: Mutable<HotComponent>) {\n if (instance.args.__hot__) {\n const state =\n instance.__get_hot_state__?.() || instance.args.__hot__.getState?.();\n for (const k in state) {\n instance[k as keyof HotComponent] = state[k];\n }\n instance.args.__hot__.getState = () => getState(instance, ['args']);\n }\n}\n\nexport function initialize() {\n const ComponentManager = getInternalComponentManager(Component);\n const proto = Object.getPrototypeOf(ComponentManager);\n const create = proto.create;\n proto.create = function (...args: any[]) {\n const instance = create.call(this, ...args);\n syncState(instance.component);\n return instance;\n };\n\n const setupController = Route.prototype.setupController;\n\n const StateCache: Record<string, any> = {};\n\n Route.prototype.setupController = function (...args: any[]) {\n const controller = args[0];\n // @ts-ignore\n const r = setupController.call(this, ...args);\n const fullRouteName = this.fullRouteName;\n const state = StateCache[fullRouteName] || {};\n const skip = ['_qpDelegate', 'target', 'queryParams'];\n const routerState = getState(state.router, skip);\n const controllerState = getState(state.controller, skip);\n for (const k in routerState) {\n (this as any)[k] = routerState[k];\n }\n for (const k in controllerState) {\n controller[k] = controllerState[k];\n }\n StateCache[fullRouteName] = {\n route: this,\n controller,\n };\n return r;\n };\n}\n\nexport default {\n initialize,\n};\n"],"names":["findPropertyDescriptor","component","key","proto","desc","Object","getOwnPropertyDescriptor","getPrototypeOf","getState","skip","state","includes","entry","Service","writable","prototype","toString","call","value","set","syncState","instance","args","__hot__","__get_hot_state__","k","initialize","ComponentManager","getInternalComponentManager","Component","create","setupController","Route","StateCache","controller","r","fullRouteName","routerState","router","controllerState","route"],"mappings":";;;;;AAeA,SAASA,sBAAsBA,CAACC,SAAiB,EAAEC,GAAW,EAAE;EAC9D,IAAIC,KAAK,GAAGF,SAAS;AACrB,EAAA,OAAOE,KAAK,EAAE;IACZ,MAAMC,IAAI,GAAGC,MAAM,CAACC,wBAAwB,CAACH,KAAK,EAAED,GAAG,CAAC;IACxD,IAAIE,IAAI,EAAE,OAAOA,IAAI;AACrBD,IAAAA,KAAK,GAAGE,MAAM,CAACE,cAAc,CAACJ,KAAK,CAAC;AACtC,EAAA;AACF;AAEA,SAASK,QAAQA,CAACP,SAAuB,EAAEQ,IAAc,EAAE;EACzD,MAAMC,KAA0B,GAAG,EAAE;EACrC,IAAI,CAACT,SAAS,EAAE;AACd,IAAA,OAAOS,KAAK;AACd,EAAA;AACA,EAAA,KAAK,MAAMR,GAAG,IAAID,SAAS,EAAE;AAC3B,IAAA,IAAIQ,IAAI,CAACE,QAAQ,CAACT,GAAG,CAAC,EAAE;AACxB,IAAA,MAAMU,KAAK,GAAGZ,sBAAsB,CAACC,SAAS,EAAEC,GAAG,CAAC;IACpD,IAAIU,KAAK,IAAI,EAAEX,SAAS,CAACC,GAAG,CAAoB,YAAYW,OAAO,CAAC,EAAE;MACpE,IACED,KAAK,CAACE,QAAQ,IACd,CAACT,MAAM,CAACU,SAAS,CAACC,QAAQ,CAACC,IAAI,CAACL,KAAK,CAACM,KAAK,CAAC,CAACP,QAAQ,CAAC,UAAU,CAAC,EACjE;AACAD,QAAAA,KAAK,CAACR,GAAG,CAAC,GAAGD,SAAS,CAACC,GAAG,CAAoB;AAChD,MAAA;MACA,IAAIU,KAAK,CAACO,GAAG,EAAE;AACbT,QAAAA,KAAK,CAACR,GAAG,CAAC,GAAGD,SAAS,CAACC,G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