@@ -2,7 +2,12 @@ import { cloneEnumerableProperty } from '@alilc/lowcode-utils';
22import adapter from '../adapter' ;
33import { IBaseRendererInstance , IRendererProps } from '../types' ;
44
5- function patchDidCatch ( Comp : any , { baseRenderer } : { baseRenderer : IBaseRendererInstance } ) {
5+ interface Options {
6+ baseRenderer : IBaseRendererInstance ;
7+ schema : any ;
8+ }
9+
10+ function patchDidCatch ( Comp : any , { baseRenderer } : Options ) {
611 if ( Comp . patchedCatch ) {
712 return ;
813 }
@@ -44,7 +49,9 @@ function patchDidCatch(Comp: any, { baseRenderer }: { baseRenderer: IBaseRendere
4449 }
4550}
4651
47- export function compWrapper ( Comp : any , options : { baseRenderer : IBaseRendererInstance } ) {
52+ const cache = new Map ( ) ;
53+
54+ export function compWrapper ( Comp : any , options : Options ) {
4855 const { createElement, Component, forwardRef } = adapter . getRuntime ( ) ;
4956 if (
5057 Comp ?. prototype ?. isReactComponent || // react
@@ -54,6 +61,11 @@ export function compWrapper(Comp: any, options: { baseRenderer: IBaseRendererIns
5461 patchDidCatch ( Comp , options ) ;
5562 return Comp ;
5663 }
64+
65+ if ( cache . has ( options . schema . id ) ) {
66+ return cache . get ( options . schema . id ) ;
67+ }
68+
5769 class Wrapper extends Component {
5870 render ( ) {
5971 return createElement ( Comp , { ...this . props , ref : this . props . forwardRef } ) ;
@@ -63,10 +75,14 @@ export function compWrapper(Comp: any, options: { baseRenderer: IBaseRendererIns
6375
6476 patchDidCatch ( Wrapper , options ) ;
6577
66- return cloneEnumerableProperty (
78+ const WrapperComponent = cloneEnumerableProperty (
6779 forwardRef ( ( props : any , ref : any ) => {
6880 return createElement ( Wrapper , { ...props , forwardRef : ref } ) ;
6981 } ) ,
7082 Comp ,
7183 ) ;
84+
85+ cache . set ( options . schema . id , WrapperComponent ) ;
86+
87+ return WrapperComponent ;
7288}
0 commit comments