-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.js
61 lines (57 loc) · 1.52 KB
/
misc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var _ = require('../util')
/**
* Apply a filter to a list of arguments.
* This is only used internally inside expressions with
* inlined filters.
*
* @param {String} id
* @param {Array} args
* @return {*}
*/
exports._applyFilter = function (id, args) {
var registry = this.$options.filters
var filter = registry[id]
_.assertAsset(filter, 'filter', id)
return (filter.read || filter).apply(this, args)
}
/**
* Resolve a component, depending on whether the component
* is defined normally or using an async factory function.
* Resolves synchronously if already resolved, otherwise
* resolves asynchronously and caches the resolved
* constructor on the factory.
*
* @param {String} id
* @param {Function} cb
*/
exports._resolveComponent = function (id, cb) {
var registry = this.$options.components
var factory = registry[id]
_.assertAsset(factory, 'component', id)
// async component factory
if (!factory.options) {
if (factory.resolved) {
// cached
cb(factory.resolved)
} else if (factory.requested) {
factory.pendingCallbacks.push(cb)
} else {
factory.requested = true
var cbs = factory.pendingCallbacks = [cb]
factory(function resolve (res) {
if (_.isPlainObject(res)) {
res = _.Vue.extend(res)
}
// cache resolved
factory.resolved = res
// invoke callbacks
for (var i = 0, l = cbs.length; i < l; i++) {
cbs[i](res)
}
})
}
} else {
// normal component
cb(factory)
}
}