diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/vue/src/core/global-api | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/vue/src/core/global-api')
| -rw-r--r-- | node_modules/vue/src/core/global-api/assets.js | 34 | ||||
| -rw-r--r-- | node_modules/vue/src/core/global-api/extend.js | 95 | ||||
| -rw-r--r-- | node_modules/vue/src/core/global-api/index.js | 62 | ||||
| -rw-r--r-- | node_modules/vue/src/core/global-api/mixin.js | 10 | ||||
| -rw-r--r-- | node_modules/vue/src/core/global-api/use.js | 23 |
5 files changed, 224 insertions, 0 deletions
diff --git a/node_modules/vue/src/core/global-api/assets.js b/node_modules/vue/src/core/global-api/assets.js new file mode 100644 index 00000000..d975a6a5 --- /dev/null +++ b/node_modules/vue/src/core/global-api/assets.js @@ -0,0 +1,34 @@ +/* @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 + } + } + }) +} diff --git a/node_modules/vue/src/core/global-api/extend.js b/node_modules/vue/src/core/global-api/extend.js new file mode 100644 index 00000000..c1bbda3f --- /dev/null +++ b/node_modules/vue/src/core/global-api/extend.js @@ -0,0 +1,95 @@ +/* @flow */ + +import { ASSET_TYPES } from 'shared/constants' +import { defineComputed, proxy } from '../instance/state' +import { extend, mergeOptions, validateComponentName } from '../util/index' + +export function initExtend (Vue: GlobalAPI) { + /** + * Each instance constructor, including Vue, has a unique + * cid. This enables us to create wrapped "child + * constructors" for prototypal inheritance and cache them. + */ + Vue.cid = 0 + let cid = 1 + + /** + * Class inheritance + */ + Vue.extend = function (extendOptions: Object): Function { + extendOptions = extendOptions || {} + const Super = this + const SuperId = Super.cid + const cachedCtors = extendOptions._Ctor || (extendOptions._Ctor = {}) + if (cachedCtors[SuperId]) { + return cachedCtors[SuperId] + } + + const name = extendOptions.name || Super.options.name + if (process.env.NODE_ENV !== 'production' && name) { + validateComponentName(name) + } + + const Sub = function VueComponent (options) { + this._init(options) + } + Sub.prototype = Object.create(Super.prototype) + Sub.prototype.constructor = Sub + Sub.cid = cid++ + Sub.options = mergeOptions( + Super.options, + extendOptions + ) + Sub['super'] = Super + + // For props and computed properties, we define the proxy getters on + // the Vue instances at extension time, on the extended prototype. This + // avoids Object.defineProperty calls for each instance created. + if (Sub.options.props) { + initProps(Sub) + } + if (Sub.options.computed) { + initComputed(Sub) + } + + // allow further extension/mixin/plugin usage + Sub.extend = Super.extend + Sub.mixin = Super.mixin + Sub.use = Super.use + + // create asset registers, so extended classes + // can have their private assets too. + ASSET_TYPES.forEach(function (type) { + Sub[type] = Super[type] + }) + // enable recursive self-lookup + if (name) { + Sub.options.components[name] = Sub + } + + // keep a reference to the super options at extension time. + // later at instantiation we can check if Super's options have + // been updated. + Sub.superOptions = Super.options + Sub.extendOptions = extendOptions + Sub.sealedOptions = extend({}, Sub.options) + + // cache constructor + cachedCtors[SuperId] = Sub + return Sub + } +} + +function initProps (Comp) { + const props = Comp.options.props + for (const key in props) { + proxy(Comp.prototype, `_props`, key) + } +} + +function initComputed (Comp) { + const computed = Comp.options.computed + for (const key in computed) { + defineComputed(Comp.prototype, key, computed[key]) + } +} diff --git a/node_modules/vue/src/core/global-api/index.js b/node_modules/vue/src/core/global-api/index.js new file mode 100644 index 00000000..03ffa0fb --- /dev/null +++ b/node_modules/vue/src/core/global-api/index.js @@ -0,0 +1,62 @@ +/* @flow */ + +import config from '../config' +import { initUse } from './use' +import { initMixin } from './mixin' +import { initExtend } from './extend' +import { initAssetRegisters } from './assets' +import { set, del } from '../observer/index' +import { ASSET_TYPES } from 'shared/constants' +import builtInComponents from '../components/index' + +import { + warn, + extend, + nextTick, + mergeOptions, + defineReactive +} from '../util/index' + +export function initGlobalAPI (Vue: GlobalAPI) { + // config + const configDef = {} + configDef.get = () => config + if (process.env.NODE_ENV !== 'production') { + configDef.set = () => { + warn( + 'Do not replace the Vue.config object, set individual fields instead.' + ) + } + } + Object.defineProperty(Vue, 'config', configDef) + + // exposed util methods. + // NOTE: these are not considered part of the public API - avoid relying on + // them unless you are aware of the risk. + Vue.util = { + warn, + extend, + mergeOptions, + defineReactive + } + + Vue.set = set + Vue.delete = del + Vue.nextTick = nextTick + + Vue.options = Object.create(null) + ASSET_TYPES.forEach(type => { + Vue.options[type + 's'] = Object.create(null) + }) + + // this is used to identify the "base" constructor to extend all plain-object + // components with in Weex's multi-instance scenarios. + Vue.options._base = Vue + + extend(Vue.options.components, builtInComponents) + + initUse(Vue) + initMixin(Vue) + initExtend(Vue) + initAssetRegisters(Vue) +} diff --git a/node_modules/vue/src/core/global-api/mixin.js b/node_modules/vue/src/core/global-api/mixin.js new file mode 100644 index 00000000..36017a32 --- /dev/null +++ b/node_modules/vue/src/core/global-api/mixin.js @@ -0,0 +1,10 @@ +/* @flow */ + +import { mergeOptions } from '../util/index' + +export function initMixin (Vue: GlobalAPI) { + Vue.mixin = function (mixin: Object) { + this.options = mergeOptions(this.options, mixin) + return this + } +} diff --git a/node_modules/vue/src/core/global-api/use.js b/node_modules/vue/src/core/global-api/use.js new file mode 100644 index 00000000..a5b69988 --- /dev/null +++ b/node_modules/vue/src/core/global-api/use.js @@ -0,0 +1,23 @@ +/* @flow */ + +import { toArray } from '../util/index' + +export function initUse (Vue: GlobalAPI) { + Vue.use = function (plugin: Function | Object) { + const installedPlugins = (this._installedPlugins || (this._installedPlugins = [])) + if (installedPlugins.indexOf(plugin) > -1) { + return this + } + + // additional parameters + const args = toArray(arguments, 1) + args.unshift(this) + if (typeof plugin.install === 'function') { + plugin.install.apply(plugin, args) + } else if (typeof plugin === 'function') { + plugin.apply(null, args) + } + installedPlugins.push(plugin) + return this + } +} |
