mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +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';
|
// 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';
|
||||||
@@ -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 { 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in new issue
Block a user