(Comp: types.IBaseRenderComponent, {
schema,
baseRenderer,
componentInfo,
scope,
}: IComponentHocInfo)
| 149 | |
| 150 | // 给每个组件包裹一个 HOC Leaf,支持组件内部属性变化,自响应渲染 |
| 151 | export function leafWrapper(Comp: types.IBaseRenderComponent, { |
| 152 | schema, |
| 153 | baseRenderer, |
| 154 | componentInfo, |
| 155 | scope, |
| 156 | }: IComponentHocInfo) { |
| 157 | const { |
| 158 | __debug, |
| 159 | __getComponentProps: getProps, |
| 160 | __getSchemaChildrenVirtualDom: getChildren, |
| 161 | __parseData, |
| 162 | } = baseRenderer; |
| 163 | const { engine } = baseRenderer.context; |
| 164 | const host = baseRenderer.props?.__host; |
| 165 | const curDocumentId = baseRenderer.props?.documentId ?? ''; |
| 166 | const curDevice = baseRenderer.props?.device ?? ''; |
| 167 | const getNode = baseRenderer.props?.getNode; |
| 168 | const container = baseRenderer.props?.__container; |
| 169 | const setSchemaChangedSymbol = baseRenderer.props?.setSchemaChangedSymbol; |
| 170 | const editor = host?.designer?.editor; |
| 171 | const runtime = adapter.getRuntime(); |
| 172 | const { forwardRef, createElement } = runtime; |
| 173 | const Component = runtime.Component as types.IGeneralConstructor< |
| 174 | IComponentHocProps, IComponentHocState |
| 175 | >; |
| 176 | |
| 177 | const componentCacheId = schema.id; |
| 178 | |
| 179 | if (!cache || (curDocumentId && curDocumentId !== cache.documentId) || (curDevice && curDevice !== cache.device)) { |
| 180 | cache?.event.forEach(event => { |
| 181 | event.dispose?.forEach((disposeFn: any) => disposeFn && disposeFn()); |
| 182 | }); |
| 183 | cache = new LeafCache(curDocumentId, curDevice); |
| 184 | } |
| 185 | |
| 186 | if (!isReactComponent(Comp)) { |
| 187 | logger.error(`${schema.componentName} component may be has errors: `, Comp); |
| 188 | } |
| 189 | |
| 190 | initRerenderEvent({ |
| 191 | schema, |
| 192 | __debug, |
| 193 | container, |
| 194 | getNode, |
| 195 | }); |
| 196 | |
| 197 | if (curDocumentId && cache.component.has(componentCacheId) && (cache.component.get(componentCacheId).Comp === Comp)) { |
| 198 | return cache.component.get(componentCacheId).LeafWrapper; |
| 199 | } |
| 200 | |
| 201 | class LeafHoc extends Component { |
| 202 | recordInfo: { |
| 203 | startTime?: number | null; |
| 204 | type?: string; |
| 205 | node?: INode; |
| 206 | } = {}; |
| 207 | |
| 208 | private curEventLeaf: INode | undefined; |
no test coverage detected
searching dependent graphs…