@@ -12,6 +12,7 @@ import { InjectionKey } from './apiInject'
|
||||
import { isFunction, NO, isObject } from '@vue/shared'
|
||||
import { warn } from './warning'
|
||||
import { createVNode, cloneVNode, VNode } from './vnode'
|
||||
import { RootHydrateFunction } from './hydration'
|
||||
|
||||
export interface App<HostElement = any> {
|
||||
config: AppConfig
|
||||
@@ -91,11 +92,11 @@ export type CreateAppFunction<HostElement> = (
|
||||
rootProps?: Data | null
|
||||
) => App<HostElement>
|
||||
|
||||
export function createAppAPI<HostNode, HostElement>(
|
||||
render: RootRenderFunction<HostNode, HostElement>,
|
||||
hydrate?: (vnode: VNode, container: Element) => void
|
||||
export function createAppAPI<HostElement>(
|
||||
render: RootRenderFunction,
|
||||
hydrate?: RootHydrateFunction
|
||||
): CreateAppFunction<HostElement> {
|
||||
return function createApp(rootComponent: Component, rootProps = null) {
|
||||
return function createApp(rootComponent, rootProps = null) {
|
||||
if (rootProps != null && !isObject(rootProps)) {
|
||||
__DEV__ && warn(`root props passed to app.mount() must be an object.`)
|
||||
rootProps = null
|
||||
@@ -107,7 +108,7 @@ export function createAppAPI<HostNode, HostElement>(
|
||||
let isMounted = false
|
||||
|
||||
const app: App = {
|
||||
_component: rootComponent,
|
||||
_component: rootComponent as Component,
|
||||
_props: rootProps,
|
||||
_container: null,
|
||||
_context: context,
|
||||
@@ -189,7 +190,7 @@ export function createAppAPI<HostNode, HostElement>(
|
||||
|
||||
mount(rootContainer: HostElement, isHydrate?: boolean): any {
|
||||
if (!isMounted) {
|
||||
const vnode = createVNode(rootComponent, rootProps)
|
||||
const vnode = createVNode(rootComponent as Component, rootProps)
|
||||
// store app context on the root VNode.
|
||||
// this will be set on the root instance on initial mount.
|
||||
vnode.appContext = context
|
||||
@@ -202,7 +203,7 @@ export function createAppAPI<HostNode, HostElement>(
|
||||
}
|
||||
|
||||
if (isHydrate && hydrate) {
|
||||
hydrate(vnode, rootContainer as any)
|
||||
hydrate(vnode as VNode<Node, Element>, rootContainer as any)
|
||||
} else {
|
||||
render(vnode, rootContainer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user