fix: fix the leaf hoc component fails to monitor Node changes, and modify the logic for get node

This commit is contained in:
liujuping 2022-09-21 10:09:38 +08:00 committed by LeoYuan 袁力皓
parent 3d41fd5d07
commit 6ee6b07a10
3 changed files with 6 additions and 4 deletions

View File

@ -5,7 +5,6 @@ import { EngineOptions } from '@alilc/lowcode-editor-core';
import { debounce } from '../utils/common';
import adapter from '../adapter';
import * as types from '../types/index';
import { parseData } from '../utils';
export interface IComponentHocInfo {
schema: any;
@ -363,12 +362,12 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
};
componentWillReceiveProps(nextProps: any) {
let { _leaf, componentId } = nextProps;
let { componentId } = nextProps;
if (nextProps.__tag === this.props.__tag) {
return null;
}
_leaf = _leaf || getNode?.(componentId);
const _leaf = getNode?.(componentId);
if (_leaf && this.curEventLeaf && _leaf !== this.curEventLeaf) {
this.disposeFunctions.forEach((fn) => fn());
this.disposeFunctions = [];

View File

@ -18,7 +18,9 @@ exports[`children this.props.children is array 1`] = `
exports[`lifecycle leaf change and make componentWillReceiveProps 1`] = `
<div>
<div
__id="text6"
__tag="222"
componentId="text6"
content="content new leaf"
>
content new leaf

View File

@ -193,9 +193,10 @@ describe('lifecycle', () => {
it('leaf change and make componentWillReceiveProps', () => {
const newTextNodeLeaf = new Node(textSchema);
nodeMap.set(textSchema.id, newTextNodeLeaf);
component.update((
<Div _leaf={DivNode}>
<Text _leaf={newTextNodeLeaf} __tag="222" content="content 123"></Text>
<Text componentId={textSchema.id} __tag="222" content="content 123"></Text>
</Div>
));