Skip to content

Commit 640027c

Browse files
committed
api
1 parent 36c40a4 commit 640027c

File tree

4 files changed

+52
-34
lines changed

4 files changed

+52
-34
lines changed

src/instance/api/dom.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
var _ = require('../../util')
1+
import {
2+
nextTick,
3+
inDoc,
4+
removeNodeRange,
5+
mapNodeRange,
6+
before,
7+
remove
8+
} from '../../util'
29

310
import {
411
beforeWithTransition,
@@ -17,7 +24,7 @@ export default function (Vue) {
1724
*/
1825

1926
Vue.prototype.$nextTick = function (fn) {
20-
_.nextTick(fn, this)
27+
nextTick(fn, this)
2128
}
2229

2330
/**
@@ -64,7 +71,7 @@ export default function (Vue) {
6471
Vue.prototype.$before = function (target, cb, withTransition) {
6572
return insert(
6673
this, target, cb, withTransition,
67-
before, beforeWithTransition
74+
beforeWithCb, beforeWithTransition
6875
)
6976
}
7077

@@ -97,24 +104,24 @@ export default function (Vue) {
97104
if (!this.$el.parentNode) {
98105
return cb && cb()
99106
}
100-
var inDoc = this._isAttached && _.inDoc(this.$el)
107+
var inDocument = this._isAttached && inDoc(this.$el)
101108
// if we are not in document, no need to check
102109
// for transitions
103-
if (!inDoc) withTransition = false
110+
if (!inDocument) withTransition = false
104111
var self = this
105112
var realCb = function () {
106-
if (inDoc) self._callHook('detached')
113+
if (inDocument) self._callHook('detached')
107114
if (cb) cb()
108115
}
109116
if (this._isFragment) {
110-
_.removeNodeRange(
117+
removeNodeRange(
111118
this._fragmentStart,
112119
this._fragmentEnd,
113120
this, this._fragment, realCb
114121
)
115122
} else {
116123
var op = withTransition === false
117-
? remove
124+
? removeWithCb
118125
: removeWithTransition
119126
op(this.$el, this, realCb)
120127
}
@@ -135,16 +142,16 @@ export default function (Vue) {
135142

136143
function insert (vm, target, cb, withTransition, op1, op2) {
137144
target = query(target)
138-
var targetIsDetached = !_.inDoc(target)
145+
var targetIsDetached = !inDoc(target)
139146
var op = withTransition === false || targetIsDetached
140147
? op1
141148
: op2
142149
var shouldCallHook =
143150
!targetIsDetached &&
144151
!vm._isAttached &&
145-
!_.inDoc(vm.$el)
152+
!inDoc(vm.$el)
146153
if (vm._isFragment) {
147-
_.mapNodeRange(vm._fragmentStart, vm._fragmentEnd, function (node) {
154+
mapNodeRange(vm._fragmentStart, vm._fragmentEnd, function (node) {
148155
op(node, target, vm)
149156
})
150157
cb && cb()
@@ -192,8 +199,8 @@ export default function (Vue) {
192199
* @param {Function} [cb]
193200
*/
194201

195-
function before (el, target, vm, cb) {
196-
_.before(el, target)
202+
function beforeWithCb (el, target, vm, cb) {
203+
before(el, target)
197204
if (cb) cb()
198205
}
199206

@@ -205,8 +212,8 @@ export default function (Vue) {
205212
* @param {Function} [cb]
206213
*/
207214

208-
function remove (el, vm, cb) {
209-
_.remove(el)
215+
function removeWithCb (el, vm, cb) {
216+
remove(el)
210217
if (cb) cb()
211218
}
212219
}

src/instance/api/events.js

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

33
export default function (Vue) {
44

@@ -93,9 +93,9 @@ export default function (Vue) {
9393
this._shouldPropagate = !cbs
9494
if (cbs) {
9595
cbs = cbs.length > 1
96-
? _.toArray(cbs)
96+
? toArray(cbs)
9797
: cbs
98-
var args = _.toArray(arguments, 1)
98+
var args = toArray(arguments, 1)
9999
for (var i = 0, l = cbs.length; i < l; i++) {
100100
var res = cbs[i].apply(this, args)
101101
if (res === true) {

src/instance/api/global.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
var _ = require('../../util')
21
import config from '../../config'
2+
import * as util from '../../util'
3+
import {
4+
set,
5+
del,
6+
nextTick,
7+
mergeOptions,
8+
classify,
9+
toArray,
10+
commonTagRE,
11+
warn,
12+
isPlainObject
13+
} from '../../util'
314

415
export default function (Vue) {
516

617
/**
718
* Expose useful internals
819
*/
920

10-
Vue.util = _
21+
Vue.util = util
1122
Vue.config = config
12-
Vue.set = _.set
13-
Vue.delete = _.del
14-
Vue.nextTick = _.nextTick
23+
Vue.set = set
24+
Vue.delete = del
25+
Vue.nextTick = nextTick
1526

1627
/**
1728
* The following are exposed for advanced usage / plugins
@@ -55,7 +66,7 @@ export default function (Vue) {
5566
Sub.prototype = Object.create(Super.prototype)
5667
Sub.prototype.constructor = Sub
5768
Sub.cid = cid++
58-
Sub.options = _.mergeOptions(
69+
Sub.options = mergeOptions(
5970
Super.options,
6071
extendOptions
6172
)
@@ -89,7 +100,7 @@ export default function (Vue) {
89100

90101
function createClass (name) {
91102
return new Function(
92-
'return function ' + _.classify(name) +
103+
'return function ' + classify(name) +
93104
' (options) { this._init(options) }'
94105
)()
95106
}
@@ -106,7 +117,7 @@ export default function (Vue) {
106117
return
107118
}
108119
// additional parameters
109-
var args = _.toArray(arguments, 1)
120+
var args = toArray(arguments, 1)
110121
args.unshift(this)
111122
if (typeof plugin.install === 'function') {
112123
plugin.install.apply(plugin, args)
@@ -123,7 +134,7 @@ export default function (Vue) {
123134
*/
124135

125136
Vue.mixin = function (mixin) {
126-
Vue.options = _.mergeOptions(Vue.options, mixin)
137+
Vue.options = mergeOptions(Vue.options, mixin)
127138
}
128139

129140
/**
@@ -141,16 +152,16 @@ export default function (Vue) {
141152
} else {
142153
/* istanbul ignore if */
143154
if (process.env.NODE_ENV !== 'production') {
144-
if (type === 'component' && _.commonTagRE.test(id)) {
145-
_.warn(
155+
if (type === 'component' && commonTagRE.test(id)) {
156+
warn(
146157
'Do not use built-in HTML elements as component ' +
147158
'id: ' + id
148159
)
149160
}
150161
}
151162
if (
152163
type === 'component' &&
153-
_.isPlainObject(definition)
164+
isPlainObject(definition)
154165
) {
155166
definition.name = id
156167
definition = Vue.extend(definition)

src/instance/api/lifecycle.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var _ = require('../../util')
1+
import { warn, query, inDoc } from '../../util'
22
var compiler = require('../../compiler')
33

44
export default function (Vue) {
@@ -15,18 +15,18 @@ export default function (Vue) {
1515

1616
Vue.prototype.$mount = function (el) {
1717
if (this._isCompiled) {
18-
process.env.NODE_ENV !== 'production' && _.warn(
18+
process.env.NODE_ENV !== 'production' && warn(
1919
'$mount() should be called only once.'
2020
)
2121
return
2222
}
23-
el = _.query(el)
23+
el = query(el)
2424
if (!el) {
2525
el = document.createElement('div')
2626
}
2727
this._compile(el)
2828
this._initDOMHooks()
29-
if (_.inDoc(this.$el)) {
29+
if (inDoc(this.$el)) {
3030
this._callHook('attached')
3131
ready.call(this)
3232
} else {

0 commit comments

Comments
 (0)