8000 model · bencode/vue@3d5beeb · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d5beeb

Browse files
committed
model
1 parent ff2c0bc commit 3d5beeb

File tree

5 files changed

+68
-52
lines changed

5 files changed

+68
-52
lines changed

src/directives/public/model/checkbox.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
var _ = require('../../../util')
1+
import {
2+
toNumber,
3+
isArray,
4+
indexOf,
5+
looseEqual
6+
} from '../../../util'
27

3-
module.exports = {
8+
export default {
49

5-
bind: function () {
10+
bind () {
611
var self = this
712
var el = this.el
813

914
this.getValue = function () {
1015
return el.hasOwnProperty('_value')
1116
? el._value
1217
: self.params.number
13-
? _.toNumber(el.value)
18+
? toNumber(el.value)
1419
: el.value
1520
}
1621

@@ -27,10 +32,10 @@ module.exports = {
2732

2833
this.listener = function () {
2934
var model = self._watcher.value
30-
if (_.isArray(model)) {
35+
if (isArray(model)) {
3136
var val = self.getValue()
3237
if (el.checked) {
33-
if (_.indexOf(model, val) < 0) {
38+
if (indexOf(model, val) < 0) {
3439
model.push(val)
3540
}
3641
} else {
@@ -47,13 +52,13 @@ module.exports = {
4752
}
4853
},
4954

50-
update: function (value) {
55+
update (value) {
5156
var el = this.el
52-
if (_.isArray(value)) {
53-
el.checked = _.indexOf(value, this.getValue()) > -1
57+
if (isArray(value)) {
58+
el.checked = indexOf(value, this.getValue()) > -1
5459
} else {
5560
if (el.hasOwnProperty('_trueValue')) {
56-
el.checked = _.looseEqual(value, el._trueValue)
61+
el.checked = looseEqual(value, el._trueValue)
5762
} else {
5863
el.checked = !!value
5964
}

src/directives/public/model/index.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
var _ = require('../../../util')
1+
import { warn, resolveAsset } from '../../../util'
2+
import text from './text'
3+
import radio from './radio'
4+
import select from './select'
5+
import checkbox from './checkbox'
26

3-
var handlers = {
4-
text: require('./text'),
5-
radio: require('./radio'),
6-
select: require('./select'),
7-
checkbox: require('./checkbox')
7+
const handlers = {
8+
text,
9+
radio,
10+
select,
11+
checkbox
812
}
913

10-
module.exports = {
14+
export default {
1115

1216
priority: 800,
1317
twoWay: true,
@@ -25,11 +29,11 @@ module.exports = {
2529
* - number
2630
*/
2731

28-
bind: function () {
32+
bind () {
2933
// friendly warning...
3034
this.checkFilters()
3135
if (this.hasRead && !this.hasWrite) {
32-
process.env.NODE_ENV !== 'production' && _.warn(
36+
process.env.NODE_ENV !== 'production' && warn(
3337
'It seems you are using a read-only filter with ' +
3438
'v-model. You might want to use a two-way filter ' +
3539
'to ensure correct behavior.'
@@ -45,7 +49,7 @@ module.exports = {
4549
} else if (tag === 'TEXTAREA') {
4650
handler = handlers.text
4751
} else {
48-
process.env.NODE_ENV !== 'production' && _.warn(
52+
process.env.NODE_ENV !== 'production' && warn(
4953
'v-model does not support element type: ' + tag
5054
)
5155
return
@@ -60,12 +64,12 @@ module.exports = {
6064
* Check read/write filter stats.
6165
*/
6266

63-
checkFilters: function () {
67+
checkFilters () {
6468
var filters = this.filters
6569
if (!filters) return
6670
var i = filters.length
6771
while (i--) {
68-
var filter = _.resolveAsset(this.vm.$options, 'filters', filters[i].name)
72+
var filter = resolveAsset(this.vm.$options, 'filters', filters[i].name)
6973
if (typeof filter === 'function' || filter.read) {
7074
this.hasRead = true
7175
}
@@ -75,7 +79,7 @@ module.exports = {
7579
}
7680
},
7781

78-
unbind: function () {
82+
unbind () {
7983
this.el.__v_model = null
8084
this._unbind && this._unbind()
8185
}

src/directives/public/model/radio.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var _ = require('../../../util')
1+
import { toNumber, looseEqual } from '../../../util'
22

3-
module.exports = {
3+
export default {
44

5-
bind: function () {
5+
bind () {
66
var self = this
77
var el = this.el
88

@@ -13,7 +13,7 @@ module.exports = {
1313
}
1414
var val = el.value
1515
if (self.params.number) {
16-
val = _.toNumber(val)
16+
val = toNumber(val)
1717
}
1818
return val
1919
}
@@ -28,7 +28,7 @@ module.exports = {
2828
}
2929
},
3030

31-
update: function (value) {
32-
this.el.checked = _.looseEqual(value, this.getValue())
31+
update (value) {
32+
this.el.checked = looseEqual(value, this.getValue())
3333
}
3434
}

src/directives/public/model/select.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var _ = require('../../../util')
1+
import { isArray, toNumber, looseEqual } from '../../../util'
22

3-
module.exports = {
3+
export default {
44

5-
bind: function () {
5+
bind () {
66
var self = this
77
var el = this.el
88

@@ -20,9 +20,9 @@ module.exports = {
2020
this.listener = function () {
2121
var value = getValue(el, multiple)
2222
value = self.params.number
23-
? _.isArray(value)
24-
? value.map(_.toNumber)
25-
: _.toNumber(value)
23+
? isArray(value)
24+
? value.map(toNumber)
25+
: toNumber(value)
2626
: value
2727
self.set(value)
2828
}
@@ -42,10 +42,10 @@ module.exports = {
4242
this.vm.$on('hook:attached', this.forceUpdate)
4343
},
4444

45-
update: function (value) {
45+
update (value) {
4646
var el = this.el
4747
el.selectedIndex = -1
48-
var multi = this.multiple && _.isArray(value)
48+
var multi = this.multiple && isArray(value)
4949
var options = el.options
5050
var i = options.length
5151
var op, val
@@ -57,12 +57,12 @@ module.exports = {
5757
/* eslint-disable eqeqeq */
5858
op.selected = multi
5959
? indexOf(value, val) > -1
60-
: _.looseEqual(value, val)
60+
: looseEqual(value, val)
6161
/* eslint-enable eqeqeq */
6262
}
6363
},
6464

65-
unbind: function () {
65+
unbind () {
6666
/* istanbul ignore next */
6767
this.vm.$off('hook:attached', this.forceUpdate)
6868
}
@@ -110,7 +110,7 @@ function getValue (el, multi, init) {
110110
function indexOf (arr, val) {
111111
var i = arr.length
112112
while (i--) {
113-
if (_.looseEqual(arr[i], val)) {
113+
if (looseEqual(arr[i], val)) {
114114
return i
115115
}
116116
}

src/directives/public/model/text.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
var _ = require('../../../util')
1+
import {
2+
isIE9,
3+
isAndroid,
4+
toNumber,
5+
_toString,
6+
nextTick,
7+
debounce as _debounce
8+
} from '../../../util'
29

3-
module.exports = {
10+
export default {
411

5-
bind: function () {
12+
bind () {
613
var self = this
714
var el = this.el
815
var isRange = el.type === 'range'
@@ -18,7 +25,7 @@ module.exports = {
1825
// Chinese, but instead triggers them for spelling
1926
// suggestions... (see Discussion/#162)
2027
var composing = false
21-
if (!_.isAndroid && !isRange) {
28+
if (!isAndroid && !isRange) {
2229
this.on('compositionstart', function () {
2330
composing = true
2431
})
@@ -52,12 +59,12 @@ module.exports = {
5259
this.listener = function () {
5360
if (composing) return
5461
var val = number || isRange
55-
? _.toNumber(el.value)
62+
? toNumber(el.value)
5663
: el.value
5764
self.set(val)
5865
// force update on next tick to avoid lock & same value
5966
// also only update when user is not typing
60-
_.nextTick(function () {
67+
nextTick(function () {
6168
if (self._bound && !self.focused) {
6269
self.update(self._watcher.value)
6370
}
@@ -66,7 +73,7 @@ module.exports = {
6673

6774
// apply debounce
6875
if (debounce) {
69-
this.listener = _.debounce(this.listener, debounce)
76+
this.listener = _debounce(this.listener, debounce)
7077
}
7178

7279
// Support jQuery events, since jQuery.trigger() doesn't
@@ -93,9 +100,9 @@ module.exports = {
93100
}
94101

95102
// IE9 doesn't fire input event on backspace/del/cut
96-
if (!lazy && _.isIE9) {
103+
if (!lazy && isIE9) {
97104
this.on('cut', function () {
98-
_.nextTick(self.listener)
105+
nextTick(self.listener)
99106
})
100107
this.on('keyup', function (e) {
101108
if (e.keyCode === 46 || e.keyCode === 8) {
@@ -113,11 +120,11 @@ module.exports = {
113120
}
114121
},
115122

116-
update: function (value) {
117-
this.el.value = _._toString(value)
123+
update (value) {
124+
this.el.value = _toString(value)
118125
},
119126

120-
unbind: function () {
127+
unbind () {
121128
var el = this.el
122129
if (this.hasjQuery) {
123130
jQuery(el).off('change', this.listener)

0 commit comments

Comments
 (0)
0