ember-vite-hmr 1.5.1 → 1.5.2
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.
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ plugins: [['ember-vite-hmr/lib/babel-plugin'], ...other];
|
|
|
39
39
|
and for `'babel-plugin-ember-template-compilation'`
|
|
40
40
|
|
|
41
41
|
```js
|
|
42
|
-
transforms: [
|
|
42
|
+
transforms: [...templateCompatSupport(), hotAstProcessor.transform],
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
## Contributing
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import Route from '@ember/routing/route';
|
|
2
2
|
import Component from '@glimmer/component';
|
|
3
3
|
import { getInternalComponentManager } from '@glimmer/manager';
|
|
4
|
-
import '@glimmer/tracking';
|
|
5
|
-
import '@glimmer/reference';
|
|
6
|
-
import '@glimmer/runtime';
|
|
4
|
+
import { tracked } from '@glimmer/tracking';
|
|
5
|
+
import { createComputeRef } from '@glimmer/reference';
|
|
6
|
+
import { curry } from '@glimmer/runtime';
|
|
7
7
|
|
|
8
|
+
(function () {
|
|
9
|
+
console.log(tracked, createComputeRef, curry);
|
|
10
|
+
})();
|
|
8
11
|
function findPropertyDescriptor(component, key) {
|
|
9
12
|
let proto = component;
|
|
10
13
|
while (proto) {
|
|
@@ -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\n// vite dep optimizer is currently broken and cannot optimize new deps, need to include this ones from start\nimport { tracked } from '@glimmer/tracking';\n// @ts-ignore\nimport { createComputeRef } from '@glimmer/reference';\n// @ts-ignore\nimport { curry } from '@glimmer/runtime';\n\n(function () {\n
|
|
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\n// vite dep optimizer is currently broken and cannot optimize new deps, need to include this ones from start\nimport { tracked } from '@glimmer/tracking';\n// @ts-ignore\nimport { createComputeRef } from '@glimmer/reference';\n// @ts-ignore\nimport { curry } from '@glimmer/runtime';\n\n(function () {\n console.log(tracked, createComputeRef, curry);\n})();\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":["console","log","tracked","createComputeRef","curry","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":";;;;;;;AAaA,CAAC,YAAY;EACXA,OAAO,CAACC,GAAG,CAACC,OAAO,EAAEC,gBAAgB,EAAEC,KAAK,CAAC,CAAA;AAC/C,CAAC,GAAG,CAAA;AAUJ,SAASC,sBAAsBA,CAACC,SAAiB,EAAEC,GAAW,EAAE;EAC9D,IAAIC,KAAK,GAAGF,SAAS,CAAA;AACrB,EAAA,OAAOE,KAAK,EAAE;IACZ,MAAMC,IAAI,GAAGC,MAAM,CAACC,wBAAwB,CAACH,KAAK,EAAED,GAAG,CAAC,CAAA;IACxD,IAAIE,IAAI,EAAE,OAAOA,IAAI,CAAA;AACrBD,IAAAA,KAAK,GAAGE,MAAM,CAACE,cAAc,CAACJ,KAAK,CAAC,CAAA;AACtC,GAAA;AACF,CAAA;AAEA,SAASK,QAAQA,CAACP,SAAuB,EAAEQ,IAAc,EAAE;EACzD,MAAMC,KAA0B,GAAG,EAAE,CAAA;EACrC,IAAI,CAACT,SAAS,EAAE;AACd,IAAA,OAAOS,KAAK,CAAA;AACd,GAAA;AACA,EAAA,KAAK,MAAMR,GAAG,IAA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