refactor: createComponentInstance needs only 1 argument
This commit is contained in:
parent
1fcde66308
commit
7d091b5e91
@ -24,9 +24,8 @@ import { warn } from './warning'
|
|||||||
let currentVNode: VNode | null = null
|
let currentVNode: VNode | null = null
|
||||||
let currentContextVNode: VNode | null = null
|
let currentContextVNode: VNode | null = null
|
||||||
|
|
||||||
export function createComponentInstance(
|
export function createComponentInstance<T extends Component>(
|
||||||
vnode: VNode,
|
vnode: VNode
|
||||||
Component: ComponentClass
|
|
||||||
): ComponentInstance {
|
): ComponentInstance {
|
||||||
// component instance creation is done in two steps.
|
// component instance creation is done in two steps.
|
||||||
// first, `initializeComponentInstance` is called inside base component
|
// first, `initializeComponentInstance` is called inside base component
|
||||||
@ -37,6 +36,7 @@ export function createComponentInstance(
|
|||||||
// always pass args in super()
|
// always pass args in super()
|
||||||
currentVNode = vnode
|
currentVNode = vnode
|
||||||
currentContextVNode = vnode.contextVNode
|
currentContextVNode = vnode.contextVNode
|
||||||
|
const Component = vnode.tag as ComponentClass
|
||||||
const instance = (vnode.children = new Component() as ComponentInstance)
|
const instance = (vnode.children = new Component() as ComponentInstance)
|
||||||
|
|
||||||
// then we finish the initialization by collecting properties set on the
|
// then we finish the initialization by collecting properties set on the
|
||||||
|
@ -11,11 +11,7 @@ import {
|
|||||||
Ref,
|
Ref,
|
||||||
VNodeChildren
|
VNodeChildren
|
||||||
} from './vdom'
|
} from './vdom'
|
||||||
import {
|
import { ComponentInstance, FunctionalComponent } from './component'
|
||||||
ComponentInstance,
|
|
||||||
FunctionalComponent,
|
|
||||||
ComponentClass
|
|
||||||
} from './component'
|
|
||||||
import { updateProps } from './componentProps'
|
import { updateProps } from './componentProps'
|
||||||
import {
|
import {
|
||||||
renderInstanceRoot,
|
renderInstanceRoot,
|
||||||
@ -229,13 +225,7 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
// kept-alive
|
// kept-alive
|
||||||
activateComponentInstance(vnode, container, endNode)
|
activateComponentInstance(vnode, container, endNode)
|
||||||
} else {
|
} else {
|
||||||
mountComponentInstance(
|
mountComponentInstance(vnode, container, isSVG, endNode)
|
||||||
vnode,
|
|
||||||
vnode.tag as ComponentClass,
|
|
||||||
container,
|
|
||||||
isSVG,
|
|
||||||
endNode
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1151,19 +1141,17 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
|
|
||||||
function mountComponentInstance(
|
function mountComponentInstance(
|
||||||
vnode: VNode,
|
vnode: VNode,
|
||||||
Component: ComponentClass,
|
|
||||||
container: RenderNode | null,
|
container: RenderNode | null,
|
||||||
isSVG: boolean,
|
isSVG: boolean,
|
||||||
endNode: RenderNode | null
|
endNode: RenderNode | null
|
||||||
): RenderNode {
|
): RenderNode {
|
||||||
// a vnode may already have an instance if this is a compat call with
|
// a vnode may already have an instance if this is a compat call with
|
||||||
// new Vue()
|
// new Vue()
|
||||||
const instance =
|
const instance = ((__COMPAT__ && vnode.children) ||
|
||||||
(__COMPAT__ && (vnode.children as ComponentInstance)) ||
|
createComponentInstance(vnode as any)) as ComponentInstance
|
||||||
createComponentInstance(vnode, Component)
|
|
||||||
|
|
||||||
// inject platform-specific unmount to keep-alive container
|
// 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
|
;(instance as any).$unmount = unmountComponentInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class Vue {
|
|||||||
// convert it to a class
|
// convert it to a class
|
||||||
const Component = createComponentClassFromOptions(options || {})
|
const Component = createComponentClassFromOptions(options || {})
|
||||||
const vnode = h(Component)
|
const vnode = h(Component)
|
||||||
const instance = createComponentInstance(vnode, Component)
|
const instance = createComponentInstance(vnode)
|
||||||
|
|
||||||
function mount(el: any) {
|
function mount(el: any) {
|
||||||
const dom = typeof el === 'string' ? document.querySelector(el) : el
|
const dom = typeof el === 'string' ? document.querySelector(el) : el
|
||||||
|
Loading…
Reference in New Issue
Block a user