mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
ui-next: restructure registry context
This commit is contained in:
4 files changed
+23
-22
No files matched your search
@@ -1,4 +1,8 @@
|
||||
export type { Context } from './src/context';
|
||||
export { usePageData } from './src/context/pageData';
|
||||
export type { PageData } from './src/context/pageData';
|
||||
export type { ComponentName } from './src/registry';
|
||||
// Context
|
||||
export { type PageData, usePageData } from './src/context/pageData';
|
||||
|
||||
// Hooks
|
||||
export { useUrl } from './src/hooks/useUrl';
|
||||
|
||||
// Registry
|
||||
export type { ComponentName, RegistryContext } from './src/registry';
|
||||
@@ -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,10 +2,10 @@ import { StrictMode } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import plugins from 'virtual:hydro-plugins';
|
||||
import App from './App';
|
||||
import { createContext } from './context';
|
||||
import { type PageData, PageDataProvider } from './context/pageData';
|
||||
import { createRegistryContext } from './registry';
|
||||
|
||||
const ctx = createContext();
|
||||
const ctx = createRegistryContext();
|
||||
for (const plugin of plugins) {
|
||||
plugin.apply(ctx);
|
||||
}
|
||||
|
||||
@@ -74,3 +74,16 @@ export function patch(name: ComponentName, cb: (props: any) => any, id?: string)
|
||||
const list = registry.patch[name] ??= [];
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user