You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							46 lines
						
					
					
						
							1.3 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							46 lines
						
					
					
						
							1.3 KiB
						
					
					
				
								import { basic } from '../mixins/basic';
							 | 
						|
								function mapKeys(source, target, map) {
							 | 
						|
								    Object.keys(map).forEach((key) => {
							 | 
						|
								        if (source[key]) {
							 | 
						|
								            target[map[key]] = source[key];
							 | 
						|
								        }
							 | 
						|
								    });
							 | 
						|
								}
							 | 
						|
								function VantComponent(vantOptions) {
							 | 
						|
								    const options = {};
							 | 
						|
								    mapKeys(vantOptions, options, {
							 | 
						|
								        data: 'data',
							 | 
						|
								        props: 'properties',
							 | 
						|
								        watch: 'observers',
							 | 
						|
								        mixins: 'behaviors',
							 | 
						|
								        methods: 'methods',
							 | 
						|
								        beforeCreate: 'created',
							 | 
						|
								        created: 'attached',
							 | 
						|
								        mounted: 'ready',
							 | 
						|
								        destroyed: 'detached',
							 | 
						|
								        classes: 'externalClasses',
							 | 
						|
								    });
							 | 
						|
								    // add default externalClasses
							 | 
						|
								    options.externalClasses = options.externalClasses || [];
							 | 
						|
								    options.externalClasses.push('custom-class');
							 | 
						|
								    // add default behaviors
							 | 
						|
								    options.behaviors = options.behaviors || [];
							 | 
						|
								    options.behaviors.push(basic);
							 | 
						|
								    // add relations
							 | 
						|
								    const { relation } = vantOptions;
							 | 
						|
								    if (relation) {
							 | 
						|
								        options.relations = relation.relations;
							 | 
						|
								        options.behaviors.push(relation.mixin);
							 | 
						|
								    }
							 | 
						|
								    // map field to form-field behavior
							 | 
						|
								    if (vantOptions.field) {
							 | 
						|
								        options.behaviors.push('wx://form-field');
							 | 
						|
								    }
							 | 
						|
								    // add default options
							 | 
						|
								    options.options = {
							 | 
						|
								        multipleSlots: true,
							 | 
						|
								        addGlobalClass: true,
							 | 
						|
								    };
							 | 
						|
								    Component(options);
							 | 
						|
								}
							 | 
						|
								export { VantComponent };
							 | 
						|
								
							 |