]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: more readable type names for watch cleanup function
authorEvan You <yyx990803@gmail.com>
Wed, 12 Jan 2022 14:07:47 +0000 (22:07 +0800)
committerEvan You <yyx990803@gmail.com>
Wed, 12 Jan 2022 14:07:47 +0000 (22:07 +0800)
packages/runtime-core/src/apiWatch.ts

index 092491d3b0d3f6a00d42a91ccecc9df2ce34dfa8..b26c3ee238861a6858702665bca458d60aeb5917 100644 (file)
@@ -40,14 +40,14 @@ import { DeprecationTypes } from './compat/compatConfig'
 import { checkCompatEnabled, isCompatEnabled } from './compat/compatConfig'
 import { ObjectWatchOptionItem } from './componentOptions'
 
-export type WatchEffect = (onInvalidate: InvalidateCbRegistrator) => void
+export type WatchEffect = (onCleanup: OnCleanup) => void
 
 export type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T)
 
 export type WatchCallback<V = any, OV = any> = (
   value: V,
   oldValue: OV,
-  onInvalidate: InvalidateCbRegistrator
+  onCleanup: OnCleanup
 ) => any
 
 type MapSources<T, Immediate> = {
@@ -62,7 +62,7 @@ type MapSources<T, Immediate> = {
     : never
 }
 
-type InvalidateCbRegistrator = (cb: () => void) => void
+type OnCleanup = (cleanupFn: () => void) => void
 
 export interface WatchOptionsBase extends DebuggerOptions {
   flush?: 'pre' | 'post' | 'sync'
@@ -242,7 +242,7 @@ function doWatch(
           source,
           instance,
           ErrorCodes.WATCH_CALLBACK,
-          [onInvalidate]
+          [onCleanup]
         )
       }
     }
@@ -272,7 +272,7 @@ function doWatch(
   }
 
   let cleanup: () => void
-  let onInvalidate: InvalidateCbRegistrator = (fn: () => void) => {
+  let onCleanup: OnCleanup = (fn: () => void) => {
     cleanup = effect.onStop = () => {
       callWithErrorHandling(fn, instance, ErrorCodes.WATCH_CLEANUP)
     }
@@ -282,14 +282,14 @@ function doWatch(
   // unless it's eager
   if (__SSR__ && isInSSRComponentSetup) {
     // we will also not call the invalidate callback (+ runner is not set up)
-    onInvalidate = NOOP
+    onCleanup = NOOP
     if (!cb) {
       getter()
     } else if (immediate) {
       callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [
         getter(),
         isMultiSource ? [] : undefined,
-        onInvalidate
+        onCleanup
       ])
     }
     return NOOP
@@ -323,7 +323,7 @@ function doWatch(
           newValue,
           // pass undefined as the old value when it's changed for the first time
           oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
-          onInvalidate
+          onCleanup
         ])
         oldValue = newValue
       }