Skip to content

Commit 61bc8e6

Browse files
committed
fix: lifeCycle events and router plugin
1 parent 37d07f1 commit 61bc8e6

34 files changed

+197
-114
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pnpm-lock.yaml
1313
deploy-space/packages
1414
deploy-space/.env
1515

16-
1716
# IDE
1817
.vscode
1918
.idea

packages/react-renderer/src/api/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createRenderer, type AppOptions } from '@alilc/lowcode-renderer-core';
22
import { type ComponentType } from 'react';
33
import { type Root, createRoot } from 'react-dom/client';
4-
import { ApplicationView, RendererContext, extension } from '../app';
4+
import { ApplicationView, RendererContext, boosts } from '../app';
55

66
export interface ReactAppOptions extends AppOptions {
77
faultComponent?: ComponentType<any>;
@@ -17,7 +17,7 @@ export const createApp = async (options: ReactAppOptions) => {
1717
// }
1818

1919
// extends boosts
20-
extension.install(boostsManager);
20+
boostsManager.extend(boosts.toExpose());
2121

2222
let root: Root | undefined;
2323

packages/react-renderer/src/api/component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createRenderer, type AppOptions } from '@alilc/lowcode-renderer-core';
22
import { FunctionComponent } from 'react';
3-
import { type LowCodeComponentProps, createComponentBySchema } from '../runtime/component';
3+
import { type LowCodeComponentProps, createComponentBySchema } from '../runtime/schema';
44
import { RendererContext } from '../app/context';
55

66
interface Render {
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Plugin, type IBoostsService } from '@alilc/lowcode-renderer-core';
1+
import { type Plugin } from '@alilc/lowcode-renderer-core';
22
import { type ComponentType, type PropsWithChildren } from 'react';
33

44
export type WrapperComponent = ComponentType<PropsWithChildren<any>>;
@@ -9,13 +9,13 @@ export interface OutletProps {
99

1010
export type Outlet = ComponentType<OutletProps>;
1111

12-
export interface ReactRendererExtensionApi {
12+
export interface ReactRendererBoostsApi {
1313
addAppWrapper(appWrapper: WrapperComponent): void;
1414

1515
setOutlet(outlet: Outlet): void;
1616
}
1717

18-
class ReactRendererExtension {
18+
class ReactRendererBoosts {
1919
private wrappers: WrapperComponent[] = [];
2020

2121
private outlet: Outlet | null = null;
@@ -28,7 +28,7 @@ class ReactRendererExtension {
2828
return this.outlet;
2929
}
3030

31-
toExpose(): ReactRendererExtensionApi {
31+
toExpose(): ReactRendererBoostsApi {
3232
return {
3333
addAppWrapper: (appWrapper) => {
3434
if (appWrapper) this.wrappers.push(appWrapper);
@@ -38,14 +38,10 @@ class ReactRendererExtension {
3838
},
3939
};
4040
}
41-
42-
install(boostsService: IBoostsService) {
43-
boostsService.extend(this.toExpose());
44-
}
4541
}
4642

47-
export const extension = new ReactRendererExtension();
43+
export const boosts = new ReactRendererBoosts();
4844

49-
export function defineRendererPlugin(plugin: Plugin<ReactRendererExtensionApi>) {
45+
export function defineRendererPlugin(plugin: Plugin<ReactRendererBoostsApi>) {
5046
return plugin;
5147
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './context';
2-
export * from './extension';
2+
export * from './boosts';
33
export * from './view';

packages/react-renderer/src/app/view.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useRenderContext } from './context';
2-
import { getComponentByName } from '../runtime/component';
3-
import { extension } from './extension';
2+
import { getComponentByName } from '../runtime/schema';
3+
import { boosts } from './boosts';
44

55
export function ApplicationView() {
66
const renderContext = useRenderContext();
77
const { schema } = renderContext;
8-
const appWrappers = extension.getAppWrappers();
9-
const Outlet = extension.getOutlet();
8+
const appWrappers = boosts.getAppWrappers();
9+
const Outlet = boosts.getOutlet();
1010

1111
if (!Outlet) return null;
1212

packages/react-renderer/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export * from './router';
55

66
export type { Spec, ProCodeComponent, LowCodeComponent } from '@alilc/lowcode-shared';
77
export type { PackageLoader, CodeScope, Plugin } from '@alilc/lowcode-renderer-core';
8-
export type { RendererExtends } from './app/extension';
8+
export type { ReactRendererBoostsApi } from './app/boosts';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './context';
22
export * from './plugin';
3+
export type * from '@alilc/lowcode-renderer-router';

packages/react-renderer/src/router/plugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineRendererPlugin } from '../app/extension';
1+
import { defineRendererPlugin } from '../app/boosts';
22
import { LifecyclePhase } from '@alilc/lowcode-renderer-core';
33
import { createRouter, type RouterOptions } from '@alilc/lowcode-renderer-router';
44
import { createRouterView } from './routerView';
@@ -29,13 +29,14 @@ export const routerPlugin = defineRendererPlugin({
2929
const router = createRouter(routerConfig);
3030

3131
boosts.codeRuntime.getScope().set('router', router);
32+
boosts.temporaryUse('router', router);
3233

3334
const RouterView = createRouterView(router);
3435

3536
boosts.addAppWrapper(RouterView);
3637
boosts.setOutlet(RouteOutlet);
3738

38-
whenLifeCylePhaseChange(LifecyclePhase.Ready).then(() => {
39+
whenLifeCylePhaseChange(LifecyclePhase.AfterInitPackageLoad).then(() => {
3940
return router.isReady();
4041
});
4142
},

packages/react-renderer/src/router/route.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useMemo } from 'react';
22
import { useRenderContext } from '../app/context';
3-
import { OutletProps } from '../app/extension';
3+
import { OutletProps } from '../app/boosts';
44
import { useRouteLocation } from './context';
5-
import { createComponentBySchema } from '../runtime/component';
5+
import { createComponentBySchema } from '../runtime/schema';
66

77
export function RouteOutlet(props: OutletProps) {
88
const context = useRenderContext();

0 commit comments

Comments
 (0)