(vantOptions: VantComponentOptions<Data, Props, Methods>)
| 14 | } |
| 15 | |
| 16 | function VantComponent< |
| 17 | Data extends WechatMiniprogram.Component.DataOption, |
| 18 | Props extends WechatMiniprogram.Component.PropertyOption, |
| 19 | Methods extends WechatMiniprogram.Component.MethodOption |
| 20 | >(vantOptions: VantComponentOptions<Data, Props, Methods>): void { |
| 21 | const options: WechatMiniprogram.Component.Options<Data, Props, Methods> = {}; |
| 22 | |
| 23 | mapKeys(vantOptions, options, { |
| 24 | data: 'data', |
| 25 | props: 'properties', |
| 26 | watch: 'observers', |
| 27 | mixins: 'behaviors', |
| 28 | methods: 'methods', |
| 29 | beforeCreate: 'created', |
| 30 | created: 'attached', |
| 31 | mounted: 'ready', |
| 32 | destroyed: 'detached', |
| 33 | classes: 'externalClasses', |
| 34 | }); |
| 35 | |
| 36 | // add default externalClasses |
| 37 | options.externalClasses = options.externalClasses || []; |
| 38 | options.externalClasses.push('custom-class'); |
| 39 | |
| 40 | // add default behaviors |
| 41 | options.behaviors = options.behaviors || []; |
| 42 | options.behaviors.push(basic); |
| 43 | |
| 44 | // add relations |
| 45 | const { relation } = vantOptions; |
| 46 | if (relation) { |
| 47 | options.relations = relation.relations; |
| 48 | options.behaviors.push(relation.mixin); |
| 49 | } |
| 50 | |
| 51 | // map field to form-field behavior |
| 52 | if (vantOptions.field) { |
| 53 | options.behaviors.push('wx://form-field'); |
| 54 | } |
| 55 | |
| 56 | // add default options |
| 57 | options.options = { |
| 58 | multipleSlots: true, |
| 59 | addGlobalClass: true, |
| 60 | }; |
| 61 | |
| 62 | Component(options); |
| 63 | } |
| 64 | |
| 65 | export { VantComponent }; |
no test coverage detected