refactor: inline recordEffectScope

This commit is contained in:
Evan You 2024-03-07 17:53:10 +08:00
parent 2cc5615590
commit ef2eaef3aa
2 changed files with 5 additions and 12 deletions

View File

@ -2,7 +2,7 @@ import { extend, hasChanged } from '@vue/shared'
import type { ComputedRefImpl } from './computed' import type { ComputedRefImpl } from './computed'
import type { TrackOpTypes, TriggerOpTypes } from './constants' import type { TrackOpTypes, TriggerOpTypes } from './constants'
import { type Dep, globalVersion } from './dep' import { type Dep, globalVersion } from './dep'
import { recordEffectScope } from './effectScope' import { activeEffectScope } from './effectScope'
import { warn } from './warning' import { warn } from './warning'
export type EffectScheduler = (...args: any[]) => any export type EffectScheduler = (...args: any[]) => any
@ -137,7 +137,9 @@ export class ReactiveEffect<T = any>
onTrigger?: (event: DebuggerEvent) => void onTrigger?: (event: DebuggerEvent) => void
constructor(public fn: () => T) { constructor(public fn: () => T) {
recordEffectScope(this) if (activeEffectScope && activeEffectScope.active) {
activeEffectScope.effects.push(this)
}
} }
/** /**

View File

@ -1,7 +1,7 @@
import type { ReactiveEffect } from './effect' import type { ReactiveEffect } from './effect'
import { warn } from './warning' import { warn } from './warning'
let activeEffectScope: EffectScope | undefined export let activeEffectScope: EffectScope | undefined
export class EffectScope { export class EffectScope {
/** /**
@ -120,15 +120,6 @@ export function effectScope(detached?: boolean) {
return new EffectScope(detached) 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. * Returns the current active effect scope if there is one.
* *