Skip to content

Commit 36c40a4

Browse files
committed
instance internal
1 parent ab856e3 commit 36c40a4

File tree

4 files changed

+53
-31
lines changed

4 files changed

+53
-31
lines changed

src/instance/internal/events.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
var _ = require('../../util')
2-
var inDoc = _.inDoc
3-
var eventRE = /^v-on:|^@/
1+
import {
2+
inDoc,
3+
isArray,
4+
warn
5+
} from '../../util'
6+
7+
const eventRE = /^v-on:|^@/
48

59
export default function (Vue) {
610

@@ -52,7 +56,7 @@ export default function (Vue) {
5256
var handlers, key, i, j
5357
for (key in hash) {
5458
handlers = hash[key]
55-
if (_.isArray(handlers)) {
59+
if (isArray(handlers)) {
5660
for (i = 0, j = handlers.length; i < j; i++) {
5761
register(vm, action, key, handlers[i])
5862
}
@@ -82,7 +86,7 @@ export default function (Vue) {
8286
if (method) {
8387
vm[action](key, method, options)
8488
} else {
85-
process.env.NODE_ENV !== 'production' && _.warn(
89+
process.env.NODE_ENV !== 'production' && warn(
8690
'Unknown method: "' + handler + '" when ' +
8791
'registering callback for ' + action +
8892
': "' + key + '".'

src/instance/internal/lifecycle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var _ = require('../../util')
2-
var Directive = require('../../directive')
1+
import { replace } from '../../util'
2+
import Directive from '../../directive'
33
var compiler = require('../../compiler')
44

55
export default function (Vue) {
@@ -84,7 +84,7 @@ export default function (Vue) {
8484

8585
// finally replace original
8686
if (options.replace) {
87-
_.replace(original, el)
87+
replace(original, el)
8888
}
8989

9090
this._isCompiled = true

src/instance/internal/misc.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
var _ = require('../../util')
1+
import {
2+
resolveAsset,
3+
assertAsset,
4+
isPlainObject,
5+
warn
6+
} from '../../util'
27

38
export default function (Vue) {
49

@@ -19,9 +24,9 @@ export default function (Vue) {
1924
var filter, fn, args, arg, offset, i, l, j, k
2025
for (i = 0, l = filters.length; i < l; i++) {
2126
filter = filters[i]
22-
fn = _.resolveAsset(this.$options, 'filters', filter.name)
27+
fn = resolveAsset(this.$options, 'filters', filter.name)
2328
if (process.env.NODE_ENV !== 'production') {
24-
_.assertAsset(fn, 'filter', filter.name)
29+
assertAsset(fn, 'filter', filter.name)
2530
}
2631
if (!fn) continue
2732
fn = write ? fn.write : (fn.read || fn)
@@ -53,9 +58,9 @@ export default function (Vue) {
5358
*/
5459

5560
Vue.prototype._resolveComponent = function (id, cb) {
56-
var factory = _.resolveAsset(this.$options, 'components', id)
61+
var factory = resolveAsset(this.$options, 'components', id)
5762
if (process.env.NODE_ENV !== 'production') {
58-
_.assertAsset(factory, 'component', id)
63+
assertAsset(factory, 'component', id)
5964
}
6065
if (!factory) {
6166
return
@@ -72,7 +77,7 @@ export default function (Vue) {
7277
factory.requested = true
7378
var cbs = factory.pendingCallbacks = [cb]
7479
factory(function resolve (res) {
75-
if (_.isPlainObject(res)) {
80+
if (isPlainObject(res)) {
7681
res = Vue.extend(res)
7782
}
7883
// cache resolved
@@ -82,7 +87,7 @@ export default function (Vue) {
8287
cbs[i](res)
8388
}
8489
}, function reject (reason) {
85-
process.env.NODE_ENV !== 'production' && _.warn(
90+
process.env.NODE_ENV !== 'production' && warn(
8691
'Failed to resolve async component: ' + id + '. ' +
8792
(reason ? '\nReason: ' + reason : '')
8893
)

src/instance/internal/state.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
var _ = require('../../util')
2-
var compiler = require('../../compiler')
3-
import { observe, Dep } from '../../observer'
41
import Watcher from '../../watcher'
2+
var compiler = require('../../compiler')
3+
4+
import {
5+
observe,
6+
defineReactive,
7+
Dep
8+
} from '../../observer'
9+
10+
import {
11+
warn,
12+
query,
13+
hasOwn,
14+
set,
15+
isReserved,
16+
bind
17+
} from '../../util'
518

619
export default function (Vue) {
720

@@ -30,13 +43,13 @@ export default function (Vue) {
3043
var el = options.el
3144
var props = options.props
3245
if (props && !el) {
33-
process.env.NODE_ENV !== 'production' && _.warn(
46+
process.env.NODE_ENV !== 'production' && warn(
3447
'Props will not be compiled if no `el` option is ' +
3548
'provided at instantiation.'
3649
)
3750
}
3851
// make sure to convert string selectors into element now
39-
el = options.el = _.query(el)
52+
el = options.el = query(el)
4053
this._propsUnlinkFn = el && el.nodeType === 1 && props
4154
// props must be linked in proper scope if inside v-for
4255
? compiler.compileAndLinkProps(this, el, props, this._scope)
@@ -55,15 +68,15 @@ export default function (Vue) {
5568
this._data = optionsData
5669
for (var prop in propsData) {
5770
if (process.env.NODE_ENV !== 'production' &&
58-
_.hasOwn(optionsData, prop)) {
59-
_.warn(
71+
hasOwn(optionsData, prop)) {
72+
warn(
6073
'Data field "' + prop + '" is already defined ' +
6174
'as a prop. Use prop default value instead.'
6275
)
6376
}
6477
if (this._props[prop].raw !== null ||
65-
!_.hasOwn(optionsData, prop)) {
66-
_.set(optionsData, prop, propsData[prop])
78+
!hasOwn(optionsData, prop)) {
79+
set(optionsData, prop, propsData[prop])
6780
}
6881
}
6982
}
@@ -106,7 +119,7 @@ export default function (Vue) {
106119
i = keys.length
107120
while (i--) {
108121
key = keys[i]
109-
if (!_.hasOwn(this, key)) {
122+
if (!hasOwn(this, key)) {
110123
// new property
111124
this._proxy(key)
112125
}
@@ -124,7 +137,7 @@ export default function (Vue) {
124137
*/
125138

126139
Vue.prototype._proxy = function (key) {
127-
if (!_.isReserved(key)) {
140+
if (!isReserved(key)) {
128141
// need to store ref to self here
129142
// because these getter/setters might
130143
// be called by child scopes via
@@ -150,7 +163,7 @@ export default function (Vue) {
150163
*/
151164

152165
Vue.prototype._unproxy = function (key) {
153-
if (!_.isReserved(key)) {
166+
if (!isReserved(key)) {
154167
delete this[key]
155168
}
156169
}
@@ -187,10 +200,10 @@ export default function (Vue) {
187200
def.get = userDef.get
188201
? userDef.cache !== false
189202
? makeComputedGetter(userDef.get, this)
190-
: _.bind(userDef.get, this)
203+
: bind(userDef.get, this)
191204
: noop
192205
def.set = userDef.set
193-
? _.bind(userDef.set, this)
206+
? bind(userDef.set, this)
194207
: noop
195208
}
196209
Object.defineProperty(this, key, def)
@@ -223,7 +236,7 @@ export default function (Vue) {
223236
var methods = this.$options.methods
224237
if (methods) {
225238
for (var key in methods) {
226-
this[key] = _.bind(methods[key], this)
239+
this[key] = bind(methods[key], this)
227240
}
228241
}
229242
}
@@ -236,7 +249,7 @@ export default function (Vue) {
236249
var metas = this.$options._meta
237250
if (metas) {
238251
for (var key in metas) {
239-
_.defineReactive(this, key, metas[key])
252+
defineReactive(this, key, metas[key])
240253
}
241254
}
242255
}

0 commit comments

Comments
 (0)