]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: inline recordEffectScope
authorEvan You <yyx990803@gmail.com>
Thu, 7 Mar 2024 09:53:10 +0000 (17:53 +0800)
committerEvan You <yyx990803@gmail.com>
Thu, 7 Mar 2024 09:53:10 +0000 (17:53 +0800)
packages/reactivity/src/effect.ts
packages/reactivity/src/effectScope.ts

index 1a8673a9a5ab0b8a358555bf5778783526ae14df..90db99cf77f95d4e2046c5fb6c6d7d60cb76e867 100644 (file)
@@ -2,7 +2,7 @@ import { extend, hasChanged } from '@vue/shared'
 import type { ComputedRefImpl } from './computed'
 import type { TrackOpTypes, TriggerOpTypes } from './constants'
 import { type Dep, globalVersion } from './dep'
-import { recordEffectScope } from './effectScope'
+import { activeEffectScope } from './effectScope'
 import { warn } from './warning'
 
 export type EffectScheduler = (...args: any[]) => any
@@ -137,7 +137,9 @@ export class ReactiveEffect<T = any>
   onTrigger?: (event: DebuggerEvent) => void
 
   constructor(public fn: () => T) {
-    recordEffectScope(this)
+    if (activeEffectScope && activeEffectScope.active) {
+      activeEffectScope.effects.push(this)
+    }
   }
 
   /**
index 6a3eaec9fd51a1585d9d9edec44512988bee0cbe..b9d72f44d0a1f0af3a8fc8d360bf4bf12066f33a 100644 (file)
@@ -1,7 +1,7 @@
 import type { ReactiveEffect } from './effect'
 import { warn } from './warning'
 
-let activeEffectScope: EffectScope | undefined
+export let activeEffectScope: EffectScope | undefined
 
 export class EffectScope {
   /**
@@ -120,15 +120,6 @@ export function effectScope(detached?: boolean) {
   return new EffectScope(detached)
 }
 
-export function recordEffectScope(
-  effect: ReactiveEffect,
-  scope: EffectScope | undefined = activeEffectScope,
-) {
-  if (scope && scope.active) {
-    scope.effects.push(effect)
-  }
-}
-
 /**
  * Returns the current active effect scope if there is one.
  *