fix: 兼容原来 PropStash 的 export 数据结构, 去除 undefined 等值

This commit is contained in:
lihao.ylh 2021-09-29 21:43:34 +08:00
parent 621e66dca2
commit ef5dd50bc8
2 changed files with 12 additions and 8 deletions

View File

@ -152,10 +152,15 @@ export class Prop implements IPropParent {
if (!this._items) { if (!this._items) {
return this._value; return this._value;
} }
const maps: any = {}; let maps: any;
this.items!.forEach((prop, key) => { this.items!.forEach((prop, key) => {
const v = prop.export(stage); if (!prop.isUnset()) {
maps[prop.key == null ? key : prop.key] = v; const v = prop.export(stage);
if (v != null) {
maps = maps || {};
maps[prop.key || key] = prop.export(stage);
}
}
}); });
return maps; return maps;
} }

View File

@ -129,12 +129,11 @@ export class Props implements IPropParent {
} else { } else {
this.items.forEach(item => { this.items.forEach(item => {
let name = item.key as string; let name = item.key as string;
if (name == null) { if (name == null || item.isUnset() || item.isVirtual()) return;
// todo ...spread
return;
}
let value = item.export(stage); let value = item.export(stage);
allProps[name] = value; if (value != null) {
allProps[name] = value;
}
}); });
// compatible vision // compatible vision
const transformedProps = this.transformToStatic(allProps); const transformedProps = this.transformToStatic(allProps);