types(runtime-core): simplify types in createComponentInstance() (#170)

This commit is contained in:
terencez 2019-10-10 00:17:42 +08:00 committed by Evan You
parent dadfb27eed
commit 7963c01a67

View File

@ -121,19 +121,19 @@ const emptyAppContext = createAppContext()
export function createComponentInstance( export function createComponentInstance(
vnode: VNode, vnode: VNode,
parent: ComponentInternalInstance | null parent: ComponentInternalInstance | null
): ComponentInternalInstance { ) {
// inherit parent app context - or - if root, adopt from root vnode // inherit parent app context - or - if root, adopt from root vnode
const appContext = const appContext =
(parent ? parent.appContext : vnode.appContext) || emptyAppContext (parent ? parent.appContext : vnode.appContext) || emptyAppContext
const instance = { const instance: ComponentInternalInstance = {
vnode, vnode,
parent, parent,
appContext, appContext,
type: vnode.type as Component, type: vnode.type,
root: null as any, // set later so it can point to itself root: null!, // set later so it can point to itself
next: null, next: null,
subTree: null as any, // will be set synchronously right after creation subTree: null!, // will be set synchronously right after creation
update: null as any, // will be set synchronously right after creation update: null!, // will be set synchronously right after creation
render: null, render: null,
renderProxy: null, renderProxy: null,
propsProxy: null, propsProxy: null,
@ -178,7 +178,7 @@ export function createComponentInstance(
rtc: null, rtc: null,
ec: null, ec: null,
emit: (event: string, ...args: unknown[]) => { emit: (event, ...args) => {
const props = instance.vnode.props || EMPTY_OBJ const props = instance.vnode.props || EMPTY_OBJ
const handler = props[`on${event}`] || props[`on${capitalize(event)}`] const handler = props[`on${event}`] || props[`on${capitalize(event)}`]
if (handler) { if (handler) {