wip: root instance $destroy before $mount

This commit is contained in:
Evan You 2021-05-04 11:34:15 -04:00
parent 4d62670d3d
commit 7c1e665215

View File

@ -1,6 +1,7 @@
import { import {
isReactive, isReactive,
reactive, reactive,
stop,
track, track,
TrackOpTypes, TrackOpTypes,
trigger, trigger,
@ -13,7 +14,8 @@ import {
EMPTY_OBJ, EMPTY_OBJ,
isArray, isArray,
isObject, isObject,
isString isString,
invokeArrayFns
} from '@vue/shared' } from '@vue/shared'
import { warn } from '../warning' import { warn } from '../warning'
import { cloneVNode, createVNode } from '../vnode' import { cloneVNode, createVNode } from '../vnode'
@ -467,8 +469,28 @@ export function installCompatMount(
devtoolsUnmountApp(app) devtoolsUnmountApp(app)
} }
delete app._container.__vue_app__ delete app._container.__vue_app__
} else if (__DEV__) { } else {
warn(`Cannot unmount an app that is not mounted.`) const { bum, effects, um } = instance
// beforeDestroy hooks
if (bum) {
invokeArrayFns(bum)
}
if (isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, instance)) {
instance.emit('hook:beforeDestroy')
}
// stop effects
if (effects) {
for (let i = 0; i < effects.length; i++) {
stop(effects[i])
}
}
// unmounted hook
if (um) {
invokeArrayFns(um)
}
if (isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, instance)) {
instance.emit('hook:destroyed')
}
} }
} }