ui-next: restructure registry context

This commit is contained in:
Baoshuo committed 2026-05-10 01:12:47 +08:00
1 parent 950910fa17
commit f753d1b16e
4 files changed
+23 -22

No files matched your search

+8 -4
View File
@@ -1,4 +1,8 @@
export type { Context } from './src/context'; // Context
export { usePageData } from './src/context/pageData'; export { type PageData, usePageData } from './src/context/pageData';
export type { PageData } from './src/context/pageData';
export type { ComponentName } from './src/registry'; // Hooks
export { useUrl } from './src/hooks/useUrl';
// Registry
export type { ComponentName, RegistryContext } from './src/registry';
-16
View File
@@ -1,16 +0,0 @@
import {
after, before, Component, patch,
} from '../registry';
export interface Context {
before: typeof before;
after: typeof after;
patch: typeof patch;
register: typeof Component;
}
export function createContext(): Context {
return {
before, after, patch, register: Component,
};
}
+2 -2
View File
@@ -2,10 +2,10 @@ import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client'; import { createRoot } from 'react-dom/client';
import plugins from 'virtual:hydro-plugins'; import plugins from 'virtual:hydro-plugins';
import App from './App'; import App from './App';
import { createContext } from './context';
import { type PageData, PageDataProvider } from './context/pageData'; import { type PageData, PageDataProvider } from './context/pageData';
import { createRegistryContext } from './registry';
const ctx = createContext(); const ctx = createRegistryContext();
for (const plugin of plugins) { for (const plugin of plugins) {
plugin.apply(ctx); plugin.apply(ctx);
} }
+13
View File
@@ -74,3 +74,16 @@ export function patch(name: ComponentName, cb: (props: any) => any, id?: string)
const list = registry.patch[name] ??= []; const list = registry.patch[name] ??= [];
upsert(list, { id: id ?? genId(), cb }); upsert(list, { id: id ?? genId(), cb });
} }
export interface RegistryContext {
before: typeof before;
after: typeof after;
patch: typeof patch;
register: typeof Component;
}
export function createRegistryContext(): RegistryContext {
return {
before, after, patch, register: Component,
};
}