feat(hmr): root instance reload

This commit is contained in:
Evan You
2019-12-22 12:25:04 -05:00
parent c3e1c812e3
commit eda495efd8
4 changed files with 27 additions and 10 deletions

View File

@@ -6,7 +6,7 @@ import { RootRenderFunction } from './renderer'
import { InjectionKey } from './apiInject'
import { isFunction, NO, isObject } from '@vue/shared'
import { warn } from './warning'
import { createVNode } from './vnode'
import { createVNode, cloneVNode } from './vnode'
export interface App<HostElement = any> {
config: AppConfig
@@ -47,6 +47,7 @@ export interface AppContext {
components: Record<string, Component>
directives: Record<string, Directive>
provides: Record<string | symbol, any>
reload?: () => void // HMR only
}
type PluginInstallFunction = (app: App) => any
@@ -175,6 +176,14 @@ export function createAppAPI<HostNode, HostElement>(
// store app context on the root VNode.
// this will be set on the root instance on initial mount.
vnode.appContext = context
// HMR root reload
if (__BUNDLER__ && __DEV__) {
context.reload = () => {
render(cloneVNode(vnode), rootContainer)
}
}
render(vnode, rootContainer)
isMounted = true
return vnode.component!.proxy