Skip to content

Commit

Permalink
[build] update to babel 7 (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Sep 27, 2018
1 parent bce7f20 commit 27ed2e5
Show file tree
Hide file tree
Showing 14 changed files with 635 additions and 746 deletions.
12 changes: 0 additions & 12 deletions .babelrc

This file was deleted.

14 changes: 14 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
loose: true,
modules: 'commonjs'
}
]
],
plugins: [
'@babel/plugin-syntax-dynamic-import'
]
};
10 changes: 4 additions & 6 deletions dist/badge-group/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ VantComponent({
name: 'badge',
type: 'descendant',
linked(target) {
this.data.badges.push(target);
this.badges.push(target);
this.setActive();
},
unlinked(target) {
this.data.badges = this.data.badges.filter(item => item !== target);
this.badges = this.badges.filter(item => item !== target);
this.setActive();
}
},
Expand All @@ -18,19 +18,17 @@ VantComponent({
value: 0
}
},
data: {
badges: []
},
watch: {
active: 'setActive'
},
beforeCreate() {
this.badges = [];
this.currentActive = -1;
},
methods: {
setActive(badge) {
let { active } = this.data;
const { badges } = this.data;
const { badges } = this;
if (badge) {
active = badges.indexOf(badge);
}
Expand Down
25 changes: 11 additions & 14 deletions dist/field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ VantComponent({
type: Number,
value: -1
},
value: {
type: null,
value: ''
},
type: {
type: String,
value: 'text'
Expand All @@ -51,7 +47,6 @@ VantComponent({
}
},
data: {
focused: false,
showClear: false
},
computed: {
Expand All @@ -65,42 +60,44 @@ VantComponent({
});
}
},
beforeCreate() {
this.focused = false;
},
methods: {
onInput(event) {
const { value = '' } = event.detail || {};
this.$emit('input', value);
this.$emit('change', value);
this.setData({
value,
showClear: this.getShowClear({ value })
showClear: this.getShowClear(value)
});
},
onFocus() {
this.$emit('focus');
this.focused = true;
this.setData({
focused: true,
showClear: this.getShowClear({ focused: true })
showClear: this.getShowClear()
});
},
onBlur() {
this.focused = false;
this.$emit('blur');
this.setData({
focused: false,
showClear: this.getShowClear({ focused: false })
showClear: this.getShowClear()
});
},
onClickIcon() {
this.$emit('click-icon');
},
getShowClear(options) {
const { focused = this.data.focused, value = this.data.value } = options;
return (this.data.clearable && focused && value !== '' && !this.data.readonly);
getShowClear(value) {
value = value === undefined ? this.data.value : value;
return (this.data.clearable && this.focused && value && !this.data.readonly);
},
onClear() {
this.setData({
value: '',
showClear: this.getShowClear({ value: '' })
showClear: this.getShowClear('')
});
this.$emit('input', '');
this.$emit('change', '');
Expand Down
3 changes: 0 additions & 3 deletions dist/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ VantComponent({
value: -1
}
},
data: {
value: ''
},
methods: {
onChange(event) {
this.setData({ value: event.detail });
Expand Down
3 changes: 0 additions & 3 deletions dist/stepper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ VantComponent({
value: 1
}
},
data: {
value: 0
},
created() {
this.setData({
value: this.range(this.data.value)
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
},
"homepage": "https://github.com/youzan/vant-weapp#readme",
"devDependencies": {
"@babel/core": "^7.1.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"autoprefixer": "^9.1.5",
"babel-core": "^6.26.3",
"babel-loader": "7.1.5",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-loader": "8.0.2",
"cross-env": "^5.1.4",
"css-loader": "^1.0.0",
"eslint": "^5.6.0",
Expand Down
13 changes: 5 additions & 8 deletions packages/badge-group/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ VantComponent({
name: 'badge',
type: 'descendant',
linked(target: Weapp.Component) {
this.data.badges.push(target);
this.badges.push(target);
this.setActive();
},
unlinked(target: Weapp.Component) {
this.data.badges = this.data.badges.filter(item => item !== target);
this.badges = this.badges.filter(item => item !== target);
this.setActive();
}
},
Expand All @@ -21,22 +21,19 @@ VantComponent({
}
},

data: {
badges: []
},

watch: {
active: 'setActive'
},

beforeCreate() {
this.badges = [];
this.currentActive = -1;
},

methods: {
setActive(badge) {
setActive(badge: Weapp.Component) {
let { active } = this.data;
const { badges } = this.data;
const { badges } = this;

if (badge) {
active = badges.indexOf(badge);
Expand Down
27 changes: 12 additions & 15 deletions packages/field/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ VantComponent({
type: Number,
value: -1
},
value: {
type: null,
value: ''
},
type: {
type: String,
value: 'text'
Expand All @@ -55,7 +51,6 @@ VantComponent({
},

data: {
focused: false,
showClear: false
},

Expand All @@ -71,50 +66,52 @@ VantComponent({
}
},

beforeCreate() {
this.focused = false;
},

methods: {
onInput(event: Weapp.Event) {
const { value = '' } = event.detail || {};
this.$emit('input', value);
this.$emit('change', value);
this.setData({
value,
showClear: this.getShowClear({ value })
showClear: this.getShowClear(value)
});
},

onFocus() {
this.$emit('focus');
this.focused = true;
this.setData({
focused: true,
showClear: this.getShowClear({ focused: true })
showClear: this.getShowClear()
});
},

onBlur() {
this.focused = false;
this.$emit('blur');
this.setData({
focused: false,
showClear: this.getShowClear({ focused: false })
showClear: this.getShowClear()
});
},

onClickIcon() {
this.$emit('click-icon');
},

getShowClear(options): boolean {
const { focused = this.data.focused, value = this.data.value } = options;

getShowClear(value?: string): boolean {
value = value === undefined ? this.data.value : value;
return (
this.data.clearable && focused && value !== '' && !this.data.readonly
this.data.clearable && this.focused && value && !this.data.readonly
);
},

onClear() {
this.setData({
value: '',
showClear: this.getShowClear({ value: '' })
showClear: this.getShowClear('')
});
this.$emit('input', '');
this.$emit('change', '');
Expand Down
4 changes: 0 additions & 4 deletions packages/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ VantComponent({
}
},

data: {
value: ''
},

methods: {
onChange(event: Weapp.Event) {
this.setData({ value: event.detail });
Expand Down
4 changes: 0 additions & 4 deletions packages/stepper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ VantComponent({
}
},

data: {
value: 0
},

created() {
this.setData({
value: this.range(this.data.value)
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type CombinedComponentInstance<
> = Methods &
LooseObject &
Weapp.Component &
Weapp.FormField &
ComponentInstance & {
data: Data & RecordToAny<Props> & RecordToReturn<Computed>;
};
Expand Down
7 changes: 7 additions & 0 deletions types/weapp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ declare namespace Weapp {
setData(data: any, callback?: Function): void;
}

interface FormField {
data: {
name: string;
value: any;
}
}

interface Target {
id: string;
tagName: string;
Expand Down
Loading

0 comments on commit 27ed2e5

Please sign in to comment.