mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui-next: registry hmr support
This commit is contained in:
1 file changed
+18
-7
@@ -15,14 +15,25 @@ interface PatchEntry {
|
|||||||
cb: (props: any) => any;
|
cb: (props: any) => any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const registry = {
|
function createRegistry() {
|
||||||
components: {} as Record<string, React.FC<any>>,
|
return {
|
||||||
before: {} as Record<string, BeforeAfterEntry[]>,
|
components: {} as Record<string, React.FC<any>>,
|
||||||
after: {} as Record<string, BeforeAfterEntry[]>,
|
before: {} as Record<string, BeforeAfterEntry[]>,
|
||||||
patch: {} as Record<string, PatchEntry[]>,
|
after: {} as Record<string, BeforeAfterEntry[]>,
|
||||||
};
|
patch: {} as Record<string, PatchEntry[]>,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let idCounter = 0;
|
const registry: ReturnType<typeof createRegistry> = import.meta.hot?.data?.registry ?? createRegistry();
|
||||||
|
if (import.meta.hot) import.meta.hot.data.registry = registry;
|
||||||
|
|
||||||
|
let idCounter = import.meta.hot?.data?.idCounter ?? 0;
|
||||||
|
if (import.meta.hot) {
|
||||||
|
Object.defineProperty(import.meta.hot.data, 'idCounter', {
|
||||||
|
get: () => idCounter,
|
||||||
|
set: (v: number) => { idCounter = v; },
|
||||||
|
});
|
||||||
|
}
|
||||||
function genId() { return `__auto_${++idCounter}`; }
|
function genId() { return `__auto_${++idCounter}`; }
|
||||||
|
|
||||||
function upsert<T extends { id: string }>(list: T[], entry: T) {
|
function upsert<T extends { id: string }>(list: T[], entry: T) {
|
||||||
|
|||||||
Reference in new issue
Block a user