Skip to content

Commit ef2eaef

Browse files
committed
refactor: inline recordEffectScope
1 parent 2cc5615 commit ef2eaef

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

packages/reactivity/src/effect.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { extend, hasChanged } from '@vue/shared'
22
import type { ComputedRefImpl } from './computed'
33
import type { TrackOpTypes, TriggerOpTypes } from './constants'
44
import { type Dep, globalVersion } from './dep'
5-
import { recordEffectScope } from './effectScope'
5+
import { activeEffectScope } from './effectScope'
66
import { warn } from './warning'
77

88
export type EffectScheduler = (...args: any[]) => any
@@ -137,7 +137,9 @@ export class ReactiveEffect<T = any>
137137
onTrigger?: (event: DebuggerEvent) => void
138138

139139
constructor(public fn: () => T) {
140-
recordEffectScope(this)
140+
if (activeEffectScope && activeEffectScope.active) {
141+
activeEffectScope.effects.push(this)
142+
}
141143
}
142144

143145
/**

packages/reactivity/src/effectScope.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReactiveEffect } from './effect'
22
import { warn } from './warning'
33

4-
let activeEffectScope: EffectScope | undefined
4+
export let activeEffectScope: EffectScope | undefined
55

66
export class EffectScope {
77
/**
@@ -120,15 +120,6 @@ export function effectScope(detached?: boolean) {
120120
return new EffectScope(detached)
121121
}
122122

123-
export function recordEffectScope(
124-
effect: ReactiveEffect,
125-
scope: EffectScope | undefined = activeEffectScope,
126-
) {
127-
if (scope && scope.active) {
128-
scope.effects.push(effect)
129-
}
130-
}
131-
132123
/**
133124
* Returns the current active effect scope if there is one.
134125
*

0 commit comments

Comments
 (0)