Bläddra i källkod

refactor: simplify internal component creation

Evan You 8 år sedan
förälder
incheckning
7e46683470
3 ändrade filer med 10 tillägg och 15 borttagningar
  1. 0 4
      flow/options.js
  2. 9 5
      src/core/instance/init.js
  3. 1 6
      src/core/vdom/create-component.js

+ 0 - 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;

+ 9 - 5
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

+ 1 - 6
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) {