UNPKG

1.65 kBJavaScriptView Raw
1/* @flow */
2
3import config from '../config'
4import { initUse } from './use'
5import { initMixin } from './mixin'
6import { initExtend } from './extend'
7import { initAssetRegisters } from './assets'
8import { set, del } from '../observer/index'
9import { ASSET_TYPES } from 'shared/constants'
10import builtInComponents from '../components/index'
11import { observe } from 'core/observer/index'
12
13import {
14 warn,
15 extend,
16 nextTick,
17 mergeOptions,
18 defineReactive
19} from '../util/index'
20
21export function initGlobalAPI (Vue: GlobalAPI) {
22 // config
23 const configDef = {}
24 configDef.get = () => config
25 if (process.env.NODE_ENV !== 'production') {
26 configDef.set = () => {
27 warn(
28 'Do not replace the Vue.config object, set individual fields instead.'
29 )
30 }
31 }
32 Object.defineProperty(Vue, 'config', configDef)
33
34 // exposed util methods.
35 // NOTE: these are not considered part of the public API - avoid relying on
36 // them unless you are aware of the risk.
37 Vue.util = {
38 warn,
39 extend,
40 mergeOptions,
41 defineReactive
42 }
43
44 Vue.set = set
45 Vue.delete = del
46 Vue.nextTick = nextTick
47
48 // 2.6 explicit observable API
49 Vue.observable = <T>(obj: T): T => {
50 observe(obj)
51 return obj
52 }
53
54 Vue.options = Object.create(null)
55 ASSET_TYPES.forEach(type => {
56 Vue.options[type + 's'] = Object.create(null)
57 })
58
59 // this is used to identify the "base" constructor to extend all plain-object
60 // components with in Weex's multi-instance scenarios.
61 Vue.options._base = Vue
62
63 extend(Vue.options.components, builtInComponents)
64
65 initUse(Vue)
66 initMixin(Vue)
67 initExtend(Vue)
68 initAssetRegisters(Vue)
69}