mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui-next: refactor code structure
This commit is contained in:
6 files changed
+8
-8
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
export type { Context } from './src/context';
|
export type { Context } from './src/context';
|
||||||
export { usePageData } from './src/pageData';
|
export { usePageData } from './src/context/pageData';
|
||||||
export type { PageData } from './src/pageData';
|
export type { PageData } from './src/context/pageData';
|
||||||
export type { ComponentName } from './src/registry';
|
export type { ComponentName } from './src/registry';
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { usePageData } from './pageData';
|
import { usePageData } from './context/pageData';
|
||||||
import { Component } from './registry';
|
import { Component } from './registry';
|
||||||
|
|
||||||
const AppInner = Component('page:app', () => {
|
const AppInner = Component('page:app', () => {
|
||||||
const { data } = usePageData();
|
const data = usePageData();
|
||||||
|
|
||||||
return <div>app, page:{data.name}</div>;
|
return <div>app, page:{data.name}</div>;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
after, before, Component, patch,
|
after, before, Component, patch,
|
||||||
} from './registry';
|
} from '../registry';
|
||||||
|
|
||||||
export interface Context {
|
export interface Context {
|
||||||
before: typeof before;
|
before: typeof before;
|
||||||
@@ -24,8 +24,8 @@ export function PageDataProvider({ initial, children }: { initial: PageData, chi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line react-refresh/only-export-components
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
export function usePageData(): PageDataContextValue {
|
export function usePageData(): PageData {
|
||||||
const ctx = useContext(PageDataContext);
|
const ctx = useContext(PageDataContext);
|
||||||
if (!ctx) throw new Error('usePageData must be used within PageDataProvider');
|
if (!ctx) throw new Error('usePageData must be used within PageDataProvider');
|
||||||
return ctx;
|
return ctx.data;
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ 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 { createContext } from './context';
|
||||||
import { type PageData, PageDataProvider } from './pageData';
|
import { type PageData, PageDataProvider } from './context/pageData';
|
||||||
|
|
||||||
const ctx = createContext();
|
const ctx = createContext();
|
||||||
for (const plugin of plugins) {
|
for (const plugin of plugins) {
|
||||||
|
|||||||
File renamed without changes.
Reference in new issue
Block a user