Skip to content

Commit

Permalink
chore: review
Browse files Browse the repository at this point in the history
  • Loading branch information
rudyxu1102 committed Jun 5, 2024
1 parent 275412c commit ba12cdb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/reactivity/src/effectScope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReactiveEffect } from './effect'
import { type ReactiveEffect, pauseTracking, resetTracking } from './effect'
import { warn } from './warning'

let activeEffectScope: EffectScope | undefined
Expand Down Expand Up @@ -80,6 +80,7 @@ export class EffectScope {

stop(fromParent?: boolean) {
if (this._active) {
pauseTracking()
let i, l
for (i = 0, l = this.effects.length; i < l; i++) {
this.effects[i].stop()
Expand All @@ -103,6 +104,7 @@ export class EffectScope {
}
this.parent = undefined
this._active = false
resetTracking()
}
}
}
Expand Down Expand Up @@ -147,11 +149,7 @@ export function getCurrentScope() {
*/
export function onScopeDispose(fn: () => void) {
if (activeEffectScope) {
activeEffectScope.cleanups.push(() => {
pauseTracking()
fn()
resetTracking()
})
activeEffectScope.cleanups.push(fn)
} else if (__DEV__) {
warn(
`onScopeDispose() is called when there is no active effect scope` +
Expand Down

0 comments on commit ba12cdb

Please sign in to comment.