[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: {
name: 'badge',
type: 'descendant',
linked(target) {
linked(target: Weapp.Component) {
this.data.badges.push(target);
this.setActive();
},
unlinked(target) {
unlinked(target: Weapp.Component) {
this.data.badges = this.data.badges.filter(item => item !== target);
this.setActive();
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

2
types/weapp.d.ts vendored
View File

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