]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: root instance $destroy before $mount
authorEvan You <yyx990803@gmail.com>
Tue, 4 May 2021 15:34:15 +0000 (11:34 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 4 May 2021 22:26:28 +0000 (18:26 -0400)
packages/runtime-core/src/compat/global.ts

index 4cf57743a7c9b5ef82b0829373c3962a9ddaca1e..0949d5971d2a6c9e25f97383b801f22874fc4948 100644 (file)
@@ -1,6 +1,7 @@
 import {
   isReactive,
   reactive,
+  stop,
   track,
   TrackOpTypes,
   trigger,
@@ -13,7 +14,8 @@ import {
   EMPTY_OBJ,
   isArray,
   isObject,
-  isString
+  isString,
+  invokeArrayFns
 } from '@vue/shared'
 import { warn } from '../warning'
 import { cloneVNode, createVNode } from '../vnode'
@@ -467,8 +469,28 @@ export function installCompatMount(
           devtoolsUnmountApp(app)
         }
         delete app._container.__vue_app__
-      } else if (__DEV__) {
-        warn(`Cannot unmount an app that is not mounted.`)
+      } else {
+        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')
+        }
       }
     }