mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
34 lines
668 B
TypeScript
34 lines
668 B
TypeScript
import { RenderContext, VNodeData } from 'vue';
|
|
|
|
type ObjectIndex = {
|
|
[key: string]: any;
|
|
};
|
|
|
|
type Context = RenderContext & { data: VNodeData & ObjectIndex };
|
|
|
|
type InheritContext = Partial<VNodeData> & ObjectIndex;
|
|
|
|
const inheritKey = [
|
|
'style',
|
|
'class',
|
|
'attrs',
|
|
'nativeOn',
|
|
'directives',
|
|
'staticClass',
|
|
'staticStyle'
|
|
];
|
|
|
|
const mapInheritKey: ObjectIndex = { nativeOn: 'on' };
|
|
|
|
export function inheritContext(context: Context): InheritContext {
|
|
return inheritKey.reduce(
|
|
(obj, key) => {
|
|
if (context.data[key]) {
|
|
obj[mapInheritKey[key] || key] = context.data[key];
|
|
}
|
|
return obj;
|
|
},
|
|
{} as InheritContext
|
|
);
|
|
}
|