fix: prop should return undefined when all items are undefined

This commit is contained in:
LeoYuan 袁力皓 2022-03-17 10:08:22 +08:00
parent c54f369e18
commit 5bb9ec7a1d
2 changed files with 11 additions and 2 deletions

View File

@ -159,7 +159,7 @@ export class Prop implements IPropParent {
const v = prop.export(stage);
if (v != null) {
maps = maps || {};
maps[prop.key || key] = prop.export(stage);
maps[prop.key || key] = v;
}
}
});
@ -170,9 +170,13 @@ export class Prop implements IPropParent {
if (!this._items) {
return this._value;
}
return this.items!.map((prop) => {
const values = this.items!.map((prop) => {
return prop.export(stage);
});
if (values.every(val => val === undefined)) {
return undefined;
}
return values;
}
}

View File

@ -430,6 +430,11 @@ describe('Prop 类测试', () => {
// illegal
// expect(prop.set(5, 1)).toBeNull();
});
it('should return undefined when all items are undefined', () => {
prop = new Prop(mockedPropsInst, [undefined, undefined], '___loopArgs___');
expect(prop.getValue()).toBeUndefined();
});
});
});