]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: beforeDestroy & destroyed compat
authorEvan You <yyx990803@gmail.com>
Tue, 6 Apr 2021 14:07:16 +0000 (10:07 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 7 Apr 2021 20:19:24 +0000 (16:19 -0400)
packages/runtime-core/src/compat/deprecations.ts
packages/runtime-core/src/componentOptions.ts

index 5ba5d185a9f0288f884e9c2f2a898da08844f32f..b002cd0c63d1dccf43e9b73f9958da86914e0f11 100644 (file)
@@ -20,7 +20,9 @@ export const enum DeprecationTypes {
   INSTANCE_DESTROY,
 
   OPTIONS_DATA_FN,
-  OPTIONS_DATA_MERGE
+  OPTIONS_DATA_MERGE,
+  OPTIONS_BEFORE_DESTROY,
+  OPTIONS_DESTROYED
 }
 
 type DeprecationData = {
@@ -138,6 +140,14 @@ const deprecations: Record<DeprecationTypes, DeprecationData> = {
       `Detected conflicting key "${key}" when merging "data" option values. ` +
       `In Vue 3, data keys are merged shallowly and will override one another.`,
     link: `https://v3.vuejs.org/guide/migration/data-option.html#mixin-merge-behavior-change`
+  },
+
+  [DeprecationTypes.OPTIONS_BEFORE_DESTROY]: {
+    message: `\`beforeDestroy\` has been renamed to \`beforeUnmount\`.`
+  },
+
+  [DeprecationTypes.OPTIONS_DESTROYED]: {
+    message: `\`destroyed\` has been renamed to \`unmounted\`.`
   }
 }
 
index 06fd0d50f772fed53e5fbd9cc733b38ddfe22e03..b9667ab567e1768d1d7d1fc23c923fcfc842e4ed 100644 (file)
@@ -66,6 +66,7 @@ import { VNodeChild } from './vnode'
 import { callWithAsyncErrorHandling } from './errorHandling'
 import { UnionToIntersection } from './helpers/typeUtils'
 import { deepMergeData } from './compat/data'
+import { DeprecationTypes, warnDeprecation } from './compat/deprecations'
 
 /**
  * Interface for declaring custom options.
@@ -796,19 +797,24 @@ export function applyOptions(
   if (renderTriggered) {
     onRenderTriggered(renderTriggered.bind(publicThis))
   }
-  if (__DEV__ && beforeDestroy) {
-    warn(`\`beforeDestroy\` has been renamed to \`beforeUnmount\`.`)
-  }
   if (beforeUnmount) {
     onBeforeUnmount(beforeUnmount.bind(publicThis))
   }
-  if (__DEV__ && destroyed) {
-    warn(`\`destroyed\` has been renamed to \`unmounted\`.`)
-  }
   if (unmounted) {
     onUnmounted(unmounted.bind(publicThis))
   }
 
+  if (__COMPAT__) {
+    if (beforeDestroy) {
+      __DEV__ && warnDeprecation(DeprecationTypes.OPTIONS_BEFORE_DESTROY)
+      onBeforeUnmount(beforeDestroy.bind(publicThis))
+    }
+    if (destroyed) {
+      __DEV__ && warnDeprecation(DeprecationTypes.OPTIONS_DESTROYED)
+      onUnmounted(destroyed.bind(publicThis))
+    }
+  }
+
   if (isArray(expose)) {
     if (!asMixin) {
       if (expose.length) {