Browse Source

refactor: simplify internal component creation

dev
Evan You 7 years ago
parent
commit
7e46683470
  1. 4
      flow/options.js
  2. 14
      src/core/instance/init.js
  3. 7
      src/core/vdom/create-component.js

4
flow/options.js

@ -1,11 +1,7 @@
declare type InternalComponentOptions = {
_isComponent: true;
parent: Component;
propsData: ?Object;
_parentVnode: VNode;
_parentListeners: ?Object;
_renderChildren: ?Array<VNode>;
_componentTag: ?string;
_parentElm: ?Node;
_refElm: ?Node;
render?: Function;

14
src/core/instance/init.js

@ -74,14 +74,18 @@ export function initMixin (Vue: Class<Component>) {
function initInternalComponent (vm: Component, options: InternalComponentOptions) {
const opts = vm.$options = Object.create(vm.constructor.options)
// doing this because it's faster than dynamic enumeration.
const parentVnode = options._parentVnode
opts.parent = options.parent
opts.propsData = options.propsData
opts._parentVnode = options._parentVnode
opts._parentListeners = options._parentListeners
opts._renderChildren = options._renderChildren
opts._componentTag = options._componentTag
opts._parentVnode = parentVnode
opts._parentElm = options._parentElm
opts._refElm = options._refElm
const vnodeComponentOptions = parentVnode.componentOptions
opts.propsData = vnodeComponentOptions.propsData
opts._parentListeners = vnodeComponentOptions.listeners
opts._renderChildren = vnodeComponentOptions.children
opts._componentTag = vnodeComponentOptions.tag
if (options.render) {
opts.render = options.render
opts.staticRenderFns = options.staticRenderFns

7
src/core/vdom/create-component.js

@ -200,15 +200,10 @@ export function createComponentInstanceForVnode (
parentElm?: ?Node,
refElm?: ?Node
): Component {
const vnodeComponentOptions = vnode.componentOptions
const options: InternalComponentOptions = {
_isComponent: true,
parent,
propsData: vnodeComponentOptions.propsData,
_componentTag: vnodeComponentOptions.tag,
_parentVnode: vnode,
_parentListeners: vnodeComponentOptions.listeners,
_renderChildren: vnodeComponentOptions.children,
_parentElm: parentElm || null,
_refElm: refElm || null
}
@ -218,7 +213,7 @@ export function createComponentInstanceForVnode (
options.render = inlineTemplate.render
options.staticRenderFns = inlineTemplate.staticRenderFns
}
return new vnodeComponentOptions.Ctor(options)
return new vnode.componentOptions.Ctor(options)
}
function mergeHooks (data: VNodeData) {

Loading…
Cancel
Save