mirror of
				https://gitee.com/vant-contrib/vant-weapp.git
				synced 2025-10-31 03:32:07 +08:00 
			
		
		
		
	refactor(mixins): remove observer behavior (#2640)
This commit is contained in:
		
							parent
							
								
									551b1c22a9
								
							
						
					
					
						commit
						8e1af8e420
					
				| @ -14,14 +14,26 @@ VantComponent({ | |||||||
| 
 | 
 | ||||||
|   props: { |   props: { | ||||||
|     ...pickerProps, |     ...pickerProps, | ||||||
|     value: String, |     value: { | ||||||
|  |       type: String, | ||||||
|  |       observer(value: string) { | ||||||
|  |         this.code = value; | ||||||
|  |         this.setValues(); | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|     areaList: { |     areaList: { | ||||||
|       type: Object, |       type: Object, | ||||||
|       value: {} |       value: {}, | ||||||
|  |       observer: 'setValues' | ||||||
|     }, |     }, | ||||||
|     columnsNum: { |     columnsNum: { | ||||||
|       type: null, |       type: null, | ||||||
|       value: 3 |       value: 3, | ||||||
|  |       observer(value: number) { | ||||||
|  |         this.setData({ | ||||||
|  |           displayColumns: this.data.columns.slice(0, +value) | ||||||
|  |         }); | ||||||
|  |       } | ||||||
|     }, |     }, | ||||||
|     columnsPlaceholder: { |     columnsPlaceholder: { | ||||||
|       type: Array, |       type: Array, | ||||||
| @ -43,21 +55,6 @@ VantComponent({ | |||||||
|     typeToColumnsPlaceholder: {} |     typeToColumnsPlaceholder: {} | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   watch: { |  | ||||||
|     value(value: string) { |  | ||||||
|       this.code = value; |  | ||||||
|       this.setValues(); |  | ||||||
|     }, |  | ||||||
| 
 |  | ||||||
|     areaList: 'setValues', |  | ||||||
| 
 |  | ||||||
|     columnsNum(value: number) { |  | ||||||
|       this.setData({ |  | ||||||
|         displayColumns: this.data.columns.slice(0, +value) |  | ||||||
|       }); |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
| 
 |  | ||||||
|   mounted() { |   mounted() { | ||||||
|     setTimeout(() => { |     setTimeout(() => { | ||||||
|       this.setValues(); |       this.setValues(); | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| import { basic } from '../mixins/basic'; | import { basic } from '../mixins/basic'; | ||||||
| import { observe } from '../mixins/observer/index'; |  | ||||||
| import { VantComponentOptions, CombinedComponentInstance } from 'definitions/index'; | import { VantComponentOptions, CombinedComponentInstance } from 'definitions/index'; | ||||||
| 
 | 
 | ||||||
| function mapKeys(source: object, target: object, map: object) { | function mapKeys(source: object, target: object, map: object) { | ||||||
| @ -59,7 +58,6 @@ function VantComponent<Data, Props, Methods>( | |||||||
|     addGlobalClass: true |     addGlobalClass: true | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   observe(vantOptions, options); |  | ||||||
|   Component(options); |   Component(options); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -45,11 +45,15 @@ VantComponent({ | |||||||
| 
 | 
 | ||||||
|   props: { |   props: { | ||||||
|     ...pickerProps, |     ...pickerProps, | ||||||
|     value: null, |     value: { | ||||||
|  |       type: null, | ||||||
|  |       observer: 'updateValue' | ||||||
|  |     }, | ||||||
|     filter: null, |     filter: null, | ||||||
|     type: { |     type: { | ||||||
|       type: String, |       type: String, | ||||||
|       value: 'datetime' |       value: 'datetime', | ||||||
|  |       observer: 'updateValue' | ||||||
|     }, |     }, | ||||||
|     showToolbar: { |     showToolbar: { | ||||||
|       type: Boolean, |       type: Boolean, | ||||||
| @ -61,27 +65,33 @@ VantComponent({ | |||||||
|     }, |     }, | ||||||
|     minDate: { |     minDate: { | ||||||
|       type: Number, |       type: Number, | ||||||
|       value: new Date(currentYear - 10, 0, 1).getTime() |       value: new Date(currentYear - 10, 0, 1).getTime(), | ||||||
|  |       observer: 'updateValue' | ||||||
|     }, |     }, | ||||||
|     maxDate: { |     maxDate: { | ||||||
|       type: Number, |       type: Number, | ||||||
|       value: new Date(currentYear + 10, 11, 31).getTime() |       value: new Date(currentYear + 10, 11, 31).getTime(), | ||||||
|  |       observer: 'updateValue' | ||||||
|     }, |     }, | ||||||
|     minHour: { |     minHour: { | ||||||
|       type: Number, |       type: Number, | ||||||
|       value: 0 |       value: 0, | ||||||
|  |       observer: 'updateValue' | ||||||
|     }, |     }, | ||||||
|     maxHour: { |     maxHour: { | ||||||
|       type: Number, |       type: Number, | ||||||
|       value: 23 |       value: 23, | ||||||
|  |       observer: 'updateValue' | ||||||
|     }, |     }, | ||||||
|     minMinute: { |     minMinute: { | ||||||
|       type: Number, |       type: Number, | ||||||
|       value: 0 |       value: 0, | ||||||
|  |       observer: 'updateValue' | ||||||
|     }, |     }, | ||||||
|     maxMinute: { |     maxMinute: { | ||||||
|       type: Number, |       type: Number, | ||||||
|       value: 59 |       value: 59, | ||||||
|  |       observer: 'updateValue' | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
| @ -90,17 +100,6 @@ VantComponent({ | |||||||
|     columns: [] |     columns: [] | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   watch: { |  | ||||||
|     value: 'updateValue', |  | ||||||
|     type: 'updateValue', |  | ||||||
|     minDate: 'updateValue', |  | ||||||
|     maxDate: 'updateValue', |  | ||||||
|     minHour: 'updateValue', |  | ||||||
|     maxHour: 'updateValue', |  | ||||||
|     minMinute: 'updateValue', |  | ||||||
|     maxMinute: 'updateValue' |  | ||||||
|   }, |  | ||||||
| 
 |  | ||||||
|   methods: { |   methods: { | ||||||
|     updateValue() { |     updateValue() { | ||||||
|       const { data } = this; |       const { data } = this; | ||||||
|  | |||||||
| @ -19,7 +19,6 @@ export interface VantComponentOptions<Data, Props, Methods, Instance> { | |||||||
|   classes?: string[]; |   classes?: string[]; | ||||||
|   mixins?: string[]; |   mixins?: string[]; | ||||||
|   props?: Props & Weapp.PropertyOption; |   props?: Props & Weapp.PropertyOption; | ||||||
|   watch?: Weapp.WatchOption<Instance>; |  | ||||||
|   relation?: Weapp.RelationOption<Instance> & { name: string }; |   relation?: Weapp.RelationOption<Instance> & { name: string }; | ||||||
|   relations?: { |   relations?: { | ||||||
|     [componentName: string]: Weapp.RelationOption<Instance>; |     [componentName: string]: Weapp.RelationOption<Instance>; | ||||||
|  | |||||||
| @ -91,13 +91,6 @@ export namespace Weapp { | |||||||
|     changedPath: Array<string | number>, |     changedPath: Array<string | number>, | ||||||
|   ) => void; |   ) => void; | ||||||
| 
 | 
 | ||||||
|   /** |  | ||||||
|    * watch定义 |  | ||||||
|    */ |  | ||||||
|   export interface WatchOption<Instance> { |  | ||||||
|     [name: string]: string | Observer<Instance, any> |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   /** |   /** | ||||||
|    * methods定义,miniprogram-api-typings缺少this定义 |    * methods定义,miniprogram-api-typings缺少this定义 | ||||||
|    */ |    */ | ||||||
|  | |||||||
| @ -9,7 +9,12 @@ VantComponent({ | |||||||
|   mixins: [button, openType], |   mixins: [button, openType], | ||||||
| 
 | 
 | ||||||
|   props: { |   props: { | ||||||
|     show: Boolean, |     show: { | ||||||
|  |       type: Boolean, | ||||||
|  |       observer(show: boolean) { | ||||||
|  |         !show && this.stopLoading(); | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|     title: String, |     title: String, | ||||||
|     message: String, |     message: String, | ||||||
|     useSlot: Boolean, |     useSlot: Boolean, | ||||||
| @ -64,12 +69,6 @@ VantComponent({ | |||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   watch: { |  | ||||||
|     show(show: boolean) { |  | ||||||
|       !show && this.stopLoading(); |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
| 
 |  | ||||||
|   methods: { |   methods: { | ||||||
|     onConfirm() { |     onConfirm() { | ||||||
|       this.handleAction('confirm'); |       this.handleAction('confirm'); | ||||||
|  | |||||||
| @ -16,7 +16,15 @@ VantComponent({ | |||||||
|   classes: ['custom-class', 'loading-class', 'error-class', 'image-class'], |   classes: ['custom-class', 'loading-class', 'error-class', 'image-class'], | ||||||
| 
 | 
 | ||||||
|   props: { |   props: { | ||||||
|     src: String, |     src: { | ||||||
|  |       type: String, | ||||||
|  |       observer() { | ||||||
|  |         this.setData({ | ||||||
|  |           error: false, | ||||||
|  |           loading: true | ||||||
|  |         }); | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|     round: Boolean, |     round: Boolean, | ||||||
|     width: { |     width: { | ||||||
|       type: null, |       type: null, | ||||||
| @ -51,15 +59,6 @@ VantComponent({ | |||||||
|     loading: true |     loading: true | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   watch: { |  | ||||||
|     src() { |  | ||||||
|       this.setData({ |  | ||||||
|         error: false, |  | ||||||
|         loading: true |  | ||||||
|       }); |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
| 
 |  | ||||||
|   mounted() { |   mounted() { | ||||||
|     this.setMode(); |     this.setMode(); | ||||||
|     this.setStyle(); |     this.setStyle(); | ||||||
|  | |||||||
| @ -4,6 +4,12 @@ export const basic = Behavior({ | |||||||
|       this.triggerEvent(...args); |       this.triggerEvent(...args); | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|  |     set(data: object, callback: Function) { | ||||||
|  |       this.setData(data, callback); | ||||||
|  | 
 | ||||||
|  |       return new Promise(resolve => wx.nextTick(resolve)); | ||||||
|  |     }, | ||||||
|  | 
 | ||||||
|     getRect(selector: string, all: boolean) { |     getRect(selector: string, all: boolean) { | ||||||
|       return new Promise(resolve => { |       return new Promise(resolve => { | ||||||
|         wx.createSelectorQuery() |         wx.createSelectorQuery() | ||||||
|  | |||||||
| @ -1,9 +0,0 @@ | |||||||
| export const behavior = Behavior({ |  | ||||||
|   methods: { |  | ||||||
|     set(data: object, callback: Function) { |  | ||||||
|       this.setData(data, callback); |  | ||||||
| 
 |  | ||||||
|       return new Promise(resolve => wx.nextTick(resolve)); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| }); |  | ||||||
| @ -1,23 +0,0 @@ | |||||||
| import { behavior } from './behavior'; |  | ||||||
| 
 |  | ||||||
| export function observe(vantOptions, options) { |  | ||||||
|   const { watch } = vantOptions; |  | ||||||
| 
 |  | ||||||
|   options.behaviors.push(behavior); |  | ||||||
| 
 |  | ||||||
|   if (watch) { |  | ||||||
|     const props = options.properties || {}; |  | ||||||
|     Object.keys(watch).forEach(key => { |  | ||||||
|       if (key in props) { |  | ||||||
|         let prop = props[key]; |  | ||||||
|         if (prop === null || !('type' in prop)) { |  | ||||||
|           prop = { type: prop }; |  | ||||||
|         } |  | ||||||
|         prop.observer = watch[key]; |  | ||||||
|         props[key] = prop; |  | ||||||
|       } |  | ||||||
|     }); |  | ||||||
| 
 |  | ||||||
|     options.properties = props; |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @ -8,7 +8,12 @@ VantComponent({ | |||||||
|   props: { |   props: { | ||||||
|     text: { |     text: { | ||||||
|       type: String, |       type: String, | ||||||
|       value: '' |       value: '', | ||||||
|  |       observer() { | ||||||
|  |         wx.nextTick(() => { | ||||||
|  |           this.init(); | ||||||
|  |         }); | ||||||
|  |       }, | ||||||
|     }, |     }, | ||||||
|     mode: { |     mode: { | ||||||
|       type: String, |       type: String, | ||||||
| @ -28,7 +33,12 @@ VantComponent({ | |||||||
|     }, |     }, | ||||||
|     speed: { |     speed: { | ||||||
|       type: Number, |       type: Number, | ||||||
|       value: 50 |       value: 50, | ||||||
|  |       observer() { | ||||||
|  |         wx.nextTick(() => { | ||||||
|  |           this.init(); | ||||||
|  |         }); | ||||||
|  |       } | ||||||
|     }, |     }, | ||||||
|     scrollable: { |     scrollable: { | ||||||
|       type: Boolean, |       type: Boolean, | ||||||
| @ -53,15 +63,6 @@ VantComponent({ | |||||||
|     show: true |     show: true | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   watch: { |  | ||||||
|     text() { |  | ||||||
|       this.setData({}, this.init); |  | ||||||
|     }, |  | ||||||
|     speed() { |  | ||||||
|       this.setData({}, this.init); |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
| 
 |  | ||||||
|   created() { |   created() { | ||||||
|     this.resetAnimation = wx.createAnimation({ |     this.resetAnimation = wx.createAnimation({ | ||||||
|       duration: 0, |       duration: 0, | ||||||
|  | |||||||
| @ -18,7 +18,10 @@ VantComponent({ | |||||||
|     }, |     }, | ||||||
|     defaultIndex: { |     defaultIndex: { | ||||||
|       type: Number, |       type: Number, | ||||||
|       value: 0 |       value: 0, | ||||||
|  |       observer(value: number) { | ||||||
|  |         this.setIndex(value); | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
| @ -42,12 +45,6 @@ VantComponent({ | |||||||
|     }); |     }); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   watch: { |  | ||||||
|     defaultIndex(value: number) { |  | ||||||
|       this.setIndex(value); |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
| 
 |  | ||||||
|   methods: { |   methods: { | ||||||
|     getCount() { |     getCount() { | ||||||
|       return this.data.options.length; |       return this.data.options.length; | ||||||
|  | |||||||
| @ -12,11 +12,10 @@ VantComponent({ | |||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   props: { |   props: { | ||||||
|     gutter: Number |     gutter: { | ||||||
|   }, |       type: Number, | ||||||
| 
 |       observer: 'setGutter' | ||||||
|   watch: { |     } | ||||||
|     gutter: 'setGutter' |  | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   mounted() { |   mounted() { | ||||||
|  | |||||||
| @ -25,7 +25,10 @@ VantComponent({ | |||||||
|     }, |     }, | ||||||
|     value: { |     value: { | ||||||
|       type: Number, |       type: Number, | ||||||
|       value: 0 |       value: 0, | ||||||
|  |       observer(value: number) { | ||||||
|  |         this.updateValue(value, false); | ||||||
|  |       } | ||||||
|     }, |     }, | ||||||
|     barHeight: { |     barHeight: { | ||||||
|       type: null, |       type: null, | ||||||
| @ -33,12 +36,6 @@ VantComponent({ | |||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   watch: { |  | ||||||
|     value(value: number) { |  | ||||||
|       this.updateValue(value, false); |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
| 
 |  | ||||||
|   created() { |   created() { | ||||||
|     this.updateValue(this.data.value); |     this.updateValue(this.data.value); | ||||||
|   }, |   }, | ||||||
|  | |||||||
| @ -17,11 +17,39 @@ VantComponent({ | |||||||
|   classes: ['input-class', 'plus-class', 'minus-class'], |   classes: ['input-class', 'plus-class', 'minus-class'], | ||||||
| 
 | 
 | ||||||
|   props: { |   props: { | ||||||
|     value: null, |     value: { | ||||||
|  |       type: null, | ||||||
|  |       observer(value) { | ||||||
|  |         if (value === '') { | ||||||
|  |           return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         const newValue = this.range(value); | ||||||
|  | 
 | ||||||
|  |         if (typeof newValue === 'number' && +this.data.value !== newValue) { | ||||||
|  |           this.setData({ value: newValue }); | ||||||
|  |         } | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|     integer: Boolean, |     integer: Boolean, | ||||||
|     disabled: Boolean, |     disabled: Boolean, | ||||||
|     inputWidth: null, |     inputWidth: { | ||||||
|     buttonSize: null, |       type: null, | ||||||
|  |       observer() { | ||||||
|  |         this.setData({ | ||||||
|  |           inputStyle: this.computeInputStyle() | ||||||
|  |         }); | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     buttonSize: { | ||||||
|  |       type: null, | ||||||
|  |       observer() { | ||||||
|  |         this.setData({ | ||||||
|  |           inputStyle: this.computeInputStyle(), | ||||||
|  |           buttonStyle: this.computeButtonStyle() | ||||||
|  |         }); | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|     asyncChange: Boolean, |     asyncChange: Boolean, | ||||||
|     disableInput: Boolean, |     disableInput: Boolean, | ||||||
|     decimalLength: { |     decimalLength: { | ||||||
| @ -52,33 +80,6 @@ VantComponent({ | |||||||
|     disableMinus: Boolean |     disableMinus: Boolean | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   watch: { |  | ||||||
|     value(value) { |  | ||||||
|       if (value === '') { |  | ||||||
|         return; |  | ||||||
|       } |  | ||||||
| 
 |  | ||||||
|       const newValue = this.range(value); |  | ||||||
| 
 |  | ||||||
|       if (typeof newValue === 'number' && +this.data.value !== newValue) { |  | ||||||
|         this.setData({ value: newValue }); |  | ||||||
|       } |  | ||||||
|     }, |  | ||||||
| 
 |  | ||||||
|     inputWidth() { |  | ||||||
|       this.set({ |  | ||||||
|         inputStyle: this.computeInputStyle() |  | ||||||
|       }); |  | ||||||
|     }, |  | ||||||
| 
 |  | ||||||
|     buttonSize() { |  | ||||||
|       this.set({ |  | ||||||
|         inputStyle: this.computeInputStyle(), |  | ||||||
|         buttonStyle: this.computeButtonStyle() |  | ||||||
|       }); |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
| 
 |  | ||||||
|   data: { |   data: { | ||||||
|     focus: false, |     focus: false, | ||||||
|     inputStyle: '', |     inputStyle: '', | ||||||
|  | |||||||
| @ -7,7 +7,13 @@ VantComponent({ | |||||||
|   classes: ['node-class'], |   classes: ['node-class'], | ||||||
| 
 | 
 | ||||||
|   props: { |   props: { | ||||||
|     checked: null, |     checked: { | ||||||
|  |       type: null, | ||||||
|  |       observer(value) { | ||||||
|  |         const loadingColor = this.getLoadingColor(value); | ||||||
|  |         this.setData({ value, loadingColor }); | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|     loading: Boolean, |     loading: Boolean, | ||||||
|     disabled: Boolean, |     disabled: Boolean, | ||||||
|     activeColor: String, |     activeColor: String, | ||||||
| @ -26,13 +32,6 @@ VantComponent({ | |||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   watch: { |  | ||||||
|     checked(value) { |  | ||||||
|       const loadingColor = this.getLoadingColor(value); |  | ||||||
|       this.setData({ value, loadingColor }); |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
| 
 |  | ||||||
|   created() { |   created() { | ||||||
|     const { checked: value } = this.data; |     const { checked: value } = this.data; | ||||||
|     const loadingColor = this.getLoadingColor(value); |     const loadingColor = this.getLoadingColor(value); | ||||||
|  | |||||||
| @ -13,11 +13,26 @@ VantComponent({ | |||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   props: { |   props: { | ||||||
|     dot: Boolean, |     dot: { | ||||||
|     info: null, |       type: Boolean, | ||||||
|     title: String, |       observer: 'update' | ||||||
|     disabled: Boolean, |     }, | ||||||
|     titleStyle: String, |     info: { | ||||||
|  |       type: null, | ||||||
|  |       observer: 'update' | ||||||
|  |     }, | ||||||
|  |     title: { | ||||||
|  |       type: String, | ||||||
|  |       observer: 'update' | ||||||
|  |     }, | ||||||
|  |     disabled: { | ||||||
|  |       type: Boolean, | ||||||
|  |       observer: 'update' | ||||||
|  |     }, | ||||||
|  |     titleStyle: { | ||||||
|  |       type: String, | ||||||
|  |       observer: 'update' | ||||||
|  |     }, | ||||||
|     name: { |     name: { | ||||||
|       type: [Number, String], |       type: [Number, String], | ||||||
|       value: '', |       value: '', | ||||||
| @ -28,14 +43,6 @@ VantComponent({ | |||||||
|     active: false |     active: false | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   watch: { |  | ||||||
|     title: 'update', |  | ||||||
|     disabled: 'update', |  | ||||||
|     dot: 'update', |  | ||||||
|     info: 'update', |  | ||||||
|     titleStyle: 'update' |  | ||||||
|   }, |  | ||||||
| 
 |  | ||||||
|   methods: { |   methods: { | ||||||
|     getComputedName() { |     getComputedName() { | ||||||
|       if (this.data.name !== '') { |       if (this.data.name !== '') { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user