36f2ad0d7688db07d4aae289b9a48f4646c9f0f3ac555704980837acb439c67d7019d6695cea48bc8b45da3f28575467c964536b90df6a9013970d12be0be3 1.0 KB

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