fix(vision): 兼容原 vision proto transducers 功能

This commit is contained in:
力皓 2021-06-17 11:14:03 +08:00
parent 71ff7c698d
commit b11331fdbf

View File

@ -107,6 +107,7 @@ export class Props implements IPropParent {
if (this.items.length < 1) {
return {};
}
let allProps = {} as any;
let props: any = {};
const extras: any = {};
if (this.type === 'list') {
@ -139,6 +140,12 @@ export class Props implements IPropParent {
if (value === UNSET) {
value = undefined;
}
allProps[name] = value;
});
// compatible vision
const transformedProps = this.transformToStatic(allProps);
Object.keys(transformedProps).forEach((name) => {
const value = transformedProps[name];
if (typeof name === 'string' && name.startsWith(EXTRA_KEY_PREFIX)) {
name = getOriginalExtraKey(name);
extras[name] = value;
@ -151,6 +158,26 @@ export class Props implements IPropParent {
return { props, extras };
}
/**
* @deprecated
*/
private transformToStatic(props: any) {
let transducers = this.owner.componentMeta.prototype?.options?.transducers;
if (!transducers) {
return props;
}
if (!Array.isArray(transducers)) {
transducers = [transducers];
}
props = transducers.reduce((xprops: any, transducer: any) => {
if (transducer && typeof transducer.toStatic === 'function') {
return transducer.toStatic(xprops);
}
return xprops;
}, props);
return props;
}
/**
* path
*