8889841cindex.ts000066600000003216150441747140006240 0ustar00import 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 { observe } from 'core/observer/index' import { warn, extend, nextTick, mergeOptions, defineReactive } from '../util/index' import type { GlobalAPI } from 'types/global-api' export function initGlobalAPI(Vue: GlobalAPI) { // config const configDef: Record = {} configDef.get = () => config if (__DEV__) { 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 // 2.6 explicit observable API Vue.observable = (obj: T): T => { observe(obj) return obj } 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) } mixin.ts000066600000000400150441747140006245 0ustar00import type { GlobalAPI } from 'types/global-api' import { mergeOptions } from '../util/index' export function initMixin(Vue: GlobalAPI) { Vue.mixin = function (mixin: Object) { this.options = mergeOptions(this.options, mixin) return this } } extend.ts000066600000005447150441747140006430 0ustar00import { ASSET_TYPES } from 'shared/constants' import type { Component } from 'types/component' import type { GlobalAPI } from 'types/global-api' import { defineComputed, proxy } from '../instance/state' import { extend, mergeOptions, validateComponentName } from '../util/index' import { getComponentName } from '../vdom/create-component' 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: any): typeof Component { extendOptions = extendOptions || {} const Super = this const SuperId = Super.cid const cachedCtors = extendOptions._Ctor || (extendOptions._Ctor = {}) if (cachedCtors[SuperId]) { return cachedCtors[SuperId] } const name = getComponentName(extendOptions) || getComponentName(Super.options) if (__DEV__ && name) { validateComponentName(name) } const Sub = function VueComponent(this: any, options: any) { this._init(options) } as unknown as typeof Component 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: typeof Component) { const props = Comp.options.props for (const key in props) { proxy(Comp.prototype, `_props`, key) } } function initComputed(Comp: typeof Component) { const computed = Comp.options.computed for (const key in computed) { defineComputed(Comp.prototype, key, computed[key]) } } assets.ts000066600000002173150441747140006434 0ustar00import { ASSET_TYPES } from 'shared/constants' import type { GlobalAPI } from 'types/global-api' import { isFunction, isPlainObject, validateComponentName } from '../util/index' export function initAssetRegisters(Vue: GlobalAPI) { /** * Create asset registration methods. */ ASSET_TYPES.forEach(type => { // @ts-expect-error function is not exact same 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 (__DEV__ && type === 'component') { validateComponentName(id) } if (type === 'component' && isPlainObject(definition)) { // @ts-expect-error definition.name = definition.name || id definition = this.options._base.extend(definition) } if (type === 'directive' && isFunction(definition)) { definition = { bind: definition, update: definition } } this.options[type + 's'][id] = definition return definition } } }) } use.ts000066600000001222150441747140005720 0ustar00import type { GlobalAPI } from 'types/global-api' import { toArray, isFunction } from '../util/index' export function initUse(Vue: GlobalAPI) { Vue.use = function (plugin: Function | any) { const installedPlugins = this._installedPlugins || (this._installedPlugins = []) if (installedPlugins.indexOf(plugin) > -1) { return this } // additional parameters const args = toArray(arguments, 1) args.unshift(this) if (isFunction(plugin.install)) { plugin.install.apply(plugin, args) } else if (isFunction(plugin)) { plugin.apply(null, args) } installedPlugins.push(plugin) return this } }