Skip to content

Commit 513cc8b

Browse files
committed
refactor(effectScope): restore scope after run
1 parent 6f947c3 commit 513cc8b

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

packages/reactivity/src/effectScope.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ export class EffectScope {
2121
* removal
2222
*/
2323
private index: number | undefined
24-
/**
25-
* activeEffectScope in context not died should be recorded
26-
*/
27-
private aliveEffectScope: EffectScope | undefined
2824

2925
constructor(detached = false) {
3026
if (!detached && activeEffectScope) {
@@ -38,27 +34,24 @@ export class EffectScope {
3834

3935
run<T>(fn: () => T): T | undefined {
4036
if (this.active) {
37+
const currentEffectScope = activeEffectScope
4138
try {
42-
this.aliveEffectScope = activeEffectScope
4339
activeEffectScope = this
4440
return fn()
4541
} finally {
46-
activeEffectScope = this.aliveEffectScope
47-
delete this.aliveEffectScope
42+
activeEffectScope = currentEffectScope
4843
}
4944
} else if (__DEV__) {
5045
warn(`cannot run an inactive effect scope.`)
5146
}
5247
}
5348

5449
on() {
55-
this.aliveEffectScope = activeEffectScope
5650
activeEffectScope = this
5751
}
5852

5953
off() {
60-
activeEffectScope = this.aliveEffectScope
61-
delete this.aliveEffectScope
54+
activeEffectScope = this.parent
6255
}
6356

6457
stop(fromParent?: boolean) {

0 commit comments

Comments
 (0)