You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
|
3 years ago
|
/* @flow */
|
||
|
|
|
||
|
|
import { ASSET_TYPES } from 'shared/constants'
|
||
|
|
import { isPlainObject, validateComponentName } from '../util/index'
|
||
|
|
|
||
|
|
export function initAssetRegisters (Vue: GlobalAPI) {
|
||
|
|
/**
|
||
|
|
* Create asset registration methods.
|
||
|
|
*/
|
||
|
|
ASSET_TYPES.forEach(type => {
|
||
|
|
Vue[type] = function (
|
||
|
|
id: string,
|
||
|
|
definition: Function | Object
|
||
|
|
): Function | Object | void {
|
||
|
|
if (!definition) {
|
||
|
|
return this.options[type + 's'][id]
|
||
|
|
} else {
|
||
|
|
/* istanbul ignore if */
|
||
|
|
if (process.env.NODE_ENV !== 'production' && type === 'component') {
|
||
|
|
validateComponentName(id)
|
||
|
|
}
|
||
|
|
if (type === 'component' && isPlainObject(definition)) {
|
||
|
|
definition.name = definition.name || id
|
||
|
|
definition = this.options._base.extend(definition)
|
||
|
|
}
|
||
|
|
if (type === 'directive' && typeof definition === 'function') {
|
||
|
|
definition = { bind: definition, update: definition }
|
||
|
|
}
|
||
|
|
this.options[type + 's'][id] = definition
|
||
|
|
return definition
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|