UNPKG

1.05 kBJavaScriptView Raw
1/* @flow */
2
3import { ASSET_TYPES } from 'shared/constants'
4import { isPlainObject, validateComponentName } from '../util/index'
5
6export function initAssetRegisters (Vue: GlobalAPI) {
7 /**
8 * Create asset registration methods.
9 */
10 ASSET_TYPES.forEach(type => {
11 Vue[type] = function (
12 id: string,
13 definition: Function | Object
14 ): Function | Object | void {
15 if (!definition) {
16 return this.options[type + 's'][id]
17 } else {
18 /* istanbul ignore if */
19 if (process.env.NODE_ENV !== 'production' && type === 'component') {
20 validateComponentName(id)
21 }
22 if (type === 'component' && isPlainObject(definition)) {
23 definition.name = definition.name || id
24 definition = this.options._base.extend(definition)
25 }
26 if (type === 'directive' && typeof definition === 'function') {
27 definition = { bind: definition, update: definition }
28 }
29 this.options[type + 's'][id] = definition
30 return definition
31 }
32 }
33 })
34}