From: Evan You Date: Thu, 7 Mar 2024 09:53:10 +0000 (+0800) Subject: refactor: inline recordEffectScope X-Git-Tag: v3.5.0-alpha.1~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef2eaef3aaf7e9e5ff2697a47b41c05d2a64ed5b;p=thirdparty%2Fvuejs%2Fcore.git refactor: inline recordEffectScope --- diff --git a/packages/reactivity/src/effect.ts b/packages/reactivity/src/effect.ts index 1a8673a9a5..90db99cf77 100644 --- a/packages/reactivity/src/effect.ts +++ b/packages/reactivity/src/effect.ts @@ -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 onTrigger?: (event: DebuggerEvent) => void constructor(public fn: () => T) { - recordEffectScope(this) + if (activeEffectScope && activeEffectScope.active) { + activeEffectScope.effects.push(this) + } } /** diff --git a/packages/reactivity/src/effectScope.ts b/packages/reactivity/src/effectScope.ts index 6a3eaec9fd..b9d72f44d0 100644 --- a/packages/reactivity/src/effectScope.ts +++ b/packages/reactivity/src/effectScope.ts @@ -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. *