mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-11 18:42:56 +00:00
feat(renderer-core): optimize the judgment of whether leaf hoc has children
This commit is contained in:
parent
0e90ea81bb
commit
f10b694c42
@ -521,16 +521,11 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
|
||||
}
|
||||
|
||||
get hasChildren(): boolean {
|
||||
let { children } = this.props;
|
||||
if (this.state.childrenInState) {
|
||||
children = this.state.nodeChildren;
|
||||
if (!this.state.childrenInState) {
|
||||
return 'children' in this.props;
|
||||
}
|
||||
|
||||
if (Array.isArray(children)) {
|
||||
return Boolean(children && children.length);
|
||||
}
|
||||
|
||||
return Boolean(children);
|
||||
return true;
|
||||
}
|
||||
|
||||
get children(): any {
|
||||
@ -576,7 +571,11 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
|
||||
|
||||
delete compProps.__inner__;
|
||||
|
||||
return engine.createElement(Comp, compProps, this.hasChildren ? this.children : null);
|
||||
if (this.hasChildren) {
|
||||
return engine.createElement(Comp, compProps, this.children);
|
||||
}
|
||||
|
||||
return engine.createElement(Comp, compProps);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -504,6 +504,41 @@ describe('onChildrenChange', () => {
|
||||
DivNode.emitChildrenChange();
|
||||
makeSnapshot(component);
|
||||
});
|
||||
|
||||
it('children is 0', () => {
|
||||
DivNode.schema.children = 0
|
||||
DivNode.emitChildrenChange();
|
||||
const componentInstance = component.root;
|
||||
expect(componentInstance.findByType(components.Div).props.children).toEqual(0);
|
||||
});
|
||||
|
||||
it('children is false', () => {
|
||||
DivNode.schema.children = false
|
||||
DivNode.emitChildrenChange();
|
||||
const componentInstance = component.root;
|
||||
expect(componentInstance.findByType(components.Div).props.children).toEqual(false);
|
||||
});
|
||||
|
||||
it('children is []', () => {
|
||||
DivNode.schema.children = []
|
||||
DivNode.emitChildrenChange();
|
||||
const componentInstance = component.root;
|
||||
expect(componentInstance.findByType(components.Div).props.children).toEqual([]);
|
||||
});
|
||||
|
||||
it('children is null', () => {
|
||||
DivNode.schema.children = null
|
||||
DivNode.emitChildrenChange();
|
||||
const componentInstance = component.root;
|
||||
expect(componentInstance.findByType(components.Div).props.children).toEqual(null);
|
||||
});
|
||||
|
||||
it('children is undefined', () => {
|
||||
DivNode.schema.children = undefined;
|
||||
DivNode.emitChildrenChange();
|
||||
const componentInstance = component.root;
|
||||
expect(componentInstance.findByType(components.Div).props.children).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('not render leaf', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user