mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 19:52:51 +00:00
feat: cache lazyElement
This commit is contained in:
parent
ef99ec27dc
commit
8f3b4e69af
@ -11,8 +11,6 @@ interface IState {
|
||||
}
|
||||
|
||||
export default class LazyComponent extends Component<IProps, IState> {
|
||||
private schema: object | null = null;
|
||||
|
||||
constructor(props: IProps) {
|
||||
super(props);
|
||||
this.state = {
|
||||
@ -22,9 +20,8 @@ export default class LazyComponent extends Component<IProps, IState> {
|
||||
|
||||
public async componentDidMount() {
|
||||
const { getPageData } = this.props;
|
||||
if (getPageData && !this.schema) {
|
||||
if (getPageData && !this.state.schema) {
|
||||
const schema = await getPageData();
|
||||
this.schema = schema;
|
||||
this.setState({ schema });
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ export default abstract class Provider {
|
||||
public globalUtils: any = {};
|
||||
public routerConfig: { [key: string]: string } = {};
|
||||
public layout: { componentName: string; props: any } | null = null;
|
||||
private lazyElementsMap: { [key: string]: any } = {};
|
||||
|
||||
constructor() {
|
||||
this.init();
|
||||
@ -66,11 +67,19 @@ export default abstract class Provider {
|
||||
if (!pageId) {
|
||||
return null;
|
||||
}
|
||||
return createElement(LazyComponent as any, {
|
||||
getPageData: async () => await this.getPageData(pageId),
|
||||
key: pageId,
|
||||
...props,
|
||||
});
|
||||
if (this.lazyElementsMap[pageId]) {
|
||||
console.log('缓存');
|
||||
return this.lazyElementsMap[pageId];
|
||||
} else {
|
||||
const lazyElement = createElement(LazyComponent as any, {
|
||||
getPageData: async () => await this.getPageData(pageId),
|
||||
key: pageId,
|
||||
...props,
|
||||
});
|
||||
this.lazyElementsMap[pageId] = lazyElement;
|
||||
console.log('新组件');
|
||||
return lazyElement;
|
||||
}
|
||||
}
|
||||
|
||||
public createApp() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user