[improvement] types (#648)

This commit is contained in:
neverland 2018-09-26 19:58:30 +08:00 committed by GitHub
parent a3539e373d
commit 0c4e200d40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 26 additions and 26 deletions

View File

@ -4,11 +4,11 @@ VantComponent({
relation: { relation: {
name: 'badge', name: 'badge',
type: 'descendant', type: 'descendant',
linked(target) { linked(target: Weapp.Component) {
this.data.badges.push(target); this.data.badges.push(target);
this.setActive(); this.setActive();
}, },
unlinked(target) { unlinked(target: Weapp.Component) {
this.data.badges = this.data.badges.filter(item => item !== target); this.data.badges = this.data.badges.filter(item => item !== target);
this.setActive(); this.setActive();
} }

View File

@ -1,6 +1,6 @@
export const touch = Behavior({ export const touch = Behavior({
methods: { methods: {
touchStart(event) { touchStart(event: Weapp.TouchEvent) {
this.direction = ''; this.direction = '';
this.deltaX = 0; this.deltaX = 0;
this.deltaY = 0; this.deltaY = 0;
@ -10,7 +10,7 @@ export const touch = Behavior({
this.startY = event.touches[0].clientY; this.startY = event.touches[0].clientY;
}, },
touchMove(event) { touchMove(event: Weapp.TouchEvent) {
const touch = event.touches[0]; const touch = event.touches[0];
this.deltaX = touch.clientX - this.startX; this.deltaX = touch.clientX - this.startX;
this.deltaY = touch.clientY - this.startY; this.deltaY = touch.clientY - this.startY;

View File

@ -155,7 +155,7 @@ VantComponent({
}); });
}, },
onClick(event) { onClick(event: Weapp.Event) {
this.$emit('click', event); this.$emit('click', event);
} }
} }

View File

@ -4,7 +4,7 @@ VantComponent({
relation: { relation: {
name: 'radio', name: 'radio',
type: 'descendant', type: 'descendant',
linked(target) { linked(target: Weapp.Component) {
const { value, disabled } = this.data; const { value, disabled } = this.data;
target.setData({ target.setData({
value: value, value: value,
@ -26,7 +26,7 @@ VantComponent({
}); });
}, },
disabled(disabled) { disabled(disabled: boolean) {
const children = this.getRelationNodes('../radio/index'); const children = this.getRelationNodes('../radio/index');
children.forEach(child => { children.forEach(child => {
child.setData({ disabled: disabled || child.data.disabled }); child.setData({ disabled: disabled || child.data.disabled });

View File

@ -17,7 +17,7 @@ VantComponent({
}, },
computed: { computed: {
iconClass() { iconClass(): string {
const { disabled, name, value } = this.data; const { disabled, name, value } = this.data;
return this.classNames('van-radio__icon', { return this.classNames('van-radio__icon', {
'van-radio__icon--disabled': disabled, 'van-radio__icon--disabled': disabled,
@ -34,7 +34,7 @@ VantComponent({
instance.$emit('change', value); instance.$emit('change', value);
}, },
onChange(event) { onChange(event: Weapp.Event) {
this.emitChange(event.detail.value); this.emitChange(event.detail.value);
}, },

View File

@ -4,7 +4,7 @@ VantComponent({
relation: { relation: {
name: 'col', name: 'col',
type: 'descendant', type: 'descendant',
linked(target) { linked(target: Weapp.Component) {
if (this.data.gutter) { if (this.data.gutter) {
target.setGutter(this.data.gutter); target.setGutter(this.data.gutter);
} }

View File

@ -27,7 +27,7 @@ VantComponent({
}, },
methods: { methods: {
onChange(event) { onChange(event: Weapp.Event) {
this.setData({ value: event.detail }); this.setData({ value: event.detail });
this.$emit('change', event.detail); this.$emit('change', event.detail);
}, },

View File

@ -33,14 +33,14 @@ VantComponent({
}, },
methods: { methods: {
onTouchStart(event) { onTouchStart(event: Weapp.TouchEvent) {
if (this.data.disabled) return; if (this.data.disabled) return;
this.touchStart(event); this.touchStart(event);
this.startValue = this.format(this.data.value); this.startValue = this.format(this.data.value);
}, },
onTouchMove(event) { onTouchMove(event: Weapp.TouchEvent) {
if (this.data.disabled) return; if (this.data.disabled) return;
this.touchMove(event); this.touchMove(event);
@ -55,7 +55,7 @@ VantComponent({
this.updateValue(this.data.value, true); this.updateValue(this.data.value, true);
}, },
onClick(event) { onClick(event: Weapp.TouchEvent) {
if (this.data.disabled) return; if (this.data.disabled) return;
this.getRect(rect => { this.getRect(rect => {

View File

@ -47,7 +47,7 @@ VantComponent({
return Math.max(Math.min(this.data.max, value), this.data.min); return Math.max(Math.min(this.data.max, value), this.data.min);
}, },
onInput(event) { onInput(event: Weapp.Event) {
const { value = '' } = event.detail || {}; const { value = '' } = event.detail || {};
this.triggerInput(value); this.triggerInput(value);
}, },
@ -64,7 +64,7 @@ VantComponent({
this.$emit(type); this.$emit(type);
}, },
onBlur(event) { onBlur(event: Weapp.Event) {
const value = this.range(this.data.value); const value = this.range(this.data.value);
this.triggerInput(value); this.triggerInput(value);
this.$emit('blur', event); this.$emit('blur', event);

View File

@ -41,7 +41,7 @@ VantComponent({
}, },
methods: { methods: {
onSubmit(event) { onSubmit(event: Weapp.Event) {
this.$emit('submit', event.detail); this.$emit('submit', event.detail);
} }
} }

View File

@ -26,7 +26,7 @@ VantComponent({
}, },
methods: { methods: {
onChange(event) { onChange(event: Weapp.Event) {
this.$emit('change', event.detail); this.$emit('change', event.detail);
} }
} }

View File

@ -4,13 +4,13 @@ VantComponent({
relation: { relation: {
name: 'tabbar-item', name: 'tabbar-item',
type: 'descendant', type: 'descendant',
linked(target) { linked(target: Weapp.Component) {
this.data.items.push(target); this.data.items.push(target);
setTimeout(() => { setTimeout(() => {
this.setActiveItem(); this.setActiveItem();
}); });
}, },
unlinked(target) { unlinked(target: Weapp.Component) {
this.data.items = this.data.items.filter(item => item !== target); this.data.items = this.data.items.filter(item => item !== target);
setTimeout(() => { setTimeout(() => {
this.setActiveItem(); this.setActiveItem();

View File

@ -9,14 +9,14 @@ VantComponent({
relation: { relation: {
name: 'tab', name: 'tab',
type: 'descendant', type: 'descendant',
linked(child) { linked(child: Weapp.Component) {
this.data.tabs.push({ this.data.tabs.push({
instance: child, instance: child,
data: child.data data: child.data
}); });
this.updateTabs(); this.updateTabs();
}, },
unlinked(child) { unlinked(child: Weapp.Component) {
const tabs = this.data.tabs.filter(item => item.instance !== child); const tabs = this.data.tabs.filter(item => item.instance !== child);
this.setData({ this.setData({
tabs, tabs,
@ -91,7 +91,7 @@ VantComponent({
}); });
}, },
onTap(event) { onTap(event: Weapp.Event) {
const { index } = event.currentTarget.dataset; const { index } = event.currentTarget.dataset;
if (this.data.tabs[index].data.disabled) { if (this.data.tabs[index].data.disabled) {
this.trigger('disabled', index); this.trigger('disabled', index);

View File

@ -41,12 +41,12 @@ VantComponent({
methods: { methods: {
// 当一个子项被选择时 // 当一个子项被选择时
onSelectItem(event) { onSelectItem(event: Weapp.Event) {
this.$emit('click-item', event.currentTarget.dataset.item); this.$emit('click-item', event.currentTarget.dataset.item);
}, },
// 当一个导航被点击时 // 当一个导航被点击时
onClickNav(event) { onClickNav(event: Weapp.Event) {
const { index } = event.currentTarget.dataset; const { index } = event.currentTarget.dataset;
this.$emit('click-nav', { index }); this.$emit('click-nav', { index });
}, },

2
types/weapp.d.ts vendored
View File

@ -4,7 +4,7 @@ type BehaviorOptions = {
type WX = { type WX = {
[key: string]: any [key: string]: any
} };
declare const wx: WX; declare const wx: WX;
declare function Behavior(options: BehaviorOptions): void; declare function Behavior(options: BehaviorOptions): void;