]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: createComponentInstance needs only 1 argument
authorEvan You <yyx990803@gmail.com>
Wed, 17 Oct 2018 20:37:45 +0000 (16:37 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 17 Oct 2018 20:37:45 +0000 (16:37 -0400)
packages/core/src/componentUtils.ts
packages/core/src/createRenderer.ts
packages/vue/src/index.ts

index 76a1e3e0a91375db7efc055fc2784e05bda33559..d31405812d6fbcb21ee7ac7ba3cc4daa35608eb0 100644 (file)
@@ -24,9 +24,8 @@ import { warn } from './warning'
 let currentVNode: VNode | null = null
 let currentContextVNode: VNode | null = null
 
-export function createComponentInstance(
-  vnode: VNode,
-  Component: ComponentClass
+export function createComponentInstance<T extends Component>(
+  vnode: VNode
 ): ComponentInstance {
   // component instance creation is done in two steps.
   // first, `initializeComponentInstance` is called inside base component
@@ -37,6 +36,7 @@ export function createComponentInstance(
   // always pass args in super()
   currentVNode = vnode
   currentContextVNode = vnode.contextVNode
+  const Component = vnode.tag as ComponentClass
   const instance = (vnode.children = new Component() as ComponentInstance)
 
   // then we finish the initialization by collecting properties set on the
index 963432e04f5542f67ec97c3770b5b924572bb353..b4e6f60e0e45050bef3450bce7a8c1815ef7dc9a 100644 (file)
@@ -11,11 +11,7 @@ import {
   Ref,
   VNodeChildren
 } from './vdom'
-import {
-  ComponentInstance,
-  FunctionalComponent,
-  ComponentClass
-} from './component'
+import { ComponentInstance, FunctionalComponent } from './component'
 import { updateProps } from './componentProps'
 import {
   renderInstanceRoot,
@@ -229,13 +225,7 @@ export function createRenderer(options: RendererOptions) {
       // kept-alive
       activateComponentInstance(vnode, container, endNode)
     } else {
-      mountComponentInstance(
-        vnode,
-        vnode.tag as ComponentClass,
-        container,
-        isSVG,
-        endNode
-      )
+      mountComponentInstance(vnode, container, isSVG, endNode)
     }
   }
 
@@ -1151,19 +1141,17 @@ export function createRenderer(options: RendererOptions) {
 
   function mountComponentInstance(
     vnode: VNode,
-    Component: ComponentClass,
     container: RenderNode | null,
     isSVG: boolean,
     endNode: RenderNode | null
   ): RenderNode {
     // a vnode may already have an instance if this is a compat call with
     // new Vue()
-    const instance =
-      (__COMPAT__ && (vnode.children as ComponentInstance)) ||
-      createComponentInstance(vnode, Component)
+    const instance = ((__COMPAT__ && vnode.children) ||
+      createComponentInstance(vnode as any)) as ComponentInstance
 
     // inject platform-specific unmount to keep-alive container
-    if ((Component as any)[KeepAliveSymbol] === true) {
+    if ((vnode.tag as any)[KeepAliveSymbol] === true) {
       ;(instance as any).$unmount = unmountComponentInstance
     }
 
index 72fa6708ec6ae6833dee6601f70e88c3d89eacb6..744d29b2281751825674fc4dad3a3b990c84c8fc 100644 (file)
@@ -17,7 +17,7 @@ class Vue {
     // convert it to a class
     const Component = createComponentClassFromOptions(options || {})
     const vnode = h(Component)
-    const instance = createComponentInstance(vnode, Component)
+    const instance = createComponentInstance(vnode)
 
     function mount(el: any) {
       const dom = typeof el === 'string' ? document.querySelector(el) : el