-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.js
129 lines (114 loc) · 2.68 KB
/
global.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var _ = require('../util')
var config = require('../config')
/**
* Expose useful internals
*/
exports.util = _
exports.config = config
exports.nextTick = _.nextTick
exports.compiler = require('../compiler')
exports.parsers = {
path: require('../parsers/path'),
text: require('../parsers/text'),
template: require('../parsers/template'),
directive: require('../parsers/directive'),
expression: require('../parsers/expression')
}
/**
* Each instance constructor, including Vue, has a unique
* cid. This enables us to create wrapped "child
* constructors" for prototypal inheritance and cache them.
*/
exports.cid = 0
var cid = 1
/**
* Class inheritance
*
* @param {Object} extendOptions
*/
exports.extend = function (extendOptions) {
extendOptions = extendOptions || {}
var Super = this
var Sub = createClass(
extendOptions.name ||
Super.options.name ||
'VueComponent'
)
Sub.prototype = Object.create(Super.prototype)
Sub.prototype.constructor = Sub
Sub.cid = cid++
Sub.options = _.mergeOptions(
Super.options,
extendOptions
)
Sub['super'] = Super
// allow further extension
Sub.extend = Super.extend
// create asset registers, so extended classes
// can have their private assets too.
config._assetTypes.forEach(function (type) {
Sub[type] = Super[type]
})
return Sub
}
/**
* A function that returns a sub-class constructor with the
* given name. This gives us much nicer output when
* logging instances in the console.
*
* @param {String} name
* @return {Function}
*/
function createClass (name) {
return new Function(
'return function ' + _.classify(name) +
' (options) { this._init(options) }'
)()
}
/**
* Plugin system
*
* @param {Object} plugin
*/
exports.use = function (plugin) {
// additional parameters
var args = _.toArray(arguments, 1)
args.unshift(this)
if (typeof plugin.install === 'function') {
plugin.install.apply(plugin, args)
} else {
plugin.apply(null, args)
}
return this
}
/**
* Apply a global mixin by merging it into the default
* options.
*/
exports.mixin = function (mixin) {
var Vue = _.Vue
Vue.options = _.mergeOptions(Vue.options, mixin)
}
/**
* Create asset registration methods with the following
* signature:
*
* @param {String} id
* @param {*} definition
*/
config._assetTypes.forEach(function (type) {
exports[type] = function (id, definition) {
if (!definition) {
return this.options[type + 's'][id]
} else {
if (
type === 'component' &&
_.isPlainObject(definition)
) {
definition.name = id
definition = _.Vue.extend(definition)
}
this.options[type + 's'][id] = definition
}
}
})