From 513cc8b66d0e00daa031927d2a9a2e463c89fa85 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 23 Mar 2022 11:08:39 +0100 Subject: [PATCH] refactor(effectScope): restore scope after run --- packages/reactivity/src/effectScope.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/reactivity/src/effectScope.ts b/packages/reactivity/src/effectScope.ts index 771c8b18e35..01499c5a78e 100644 --- a/packages/reactivity/src/effectScope.ts +++ b/packages/reactivity/src/effectScope.ts @@ -21,10 +21,6 @@ export class EffectScope { * removal */ private index: number | undefined - /** - * activeEffectScope in context not died should be recorded - */ - private aliveEffectScope: EffectScope | undefined constructor(detached = false) { if (!detached && activeEffectScope) { @@ -38,13 +34,12 @@ export class EffectScope { run(fn: () => T): T | undefined { if (this.active) { + const currentEffectScope = activeEffectScope try { - this.aliveEffectScope = activeEffectScope activeEffectScope = this return fn() } finally { - activeEffectScope = this.aliveEffectScope - delete this.aliveEffectScope + activeEffectScope = currentEffectScope } } else if (__DEV__) { warn(`cannot run an inactive effect scope.`) @@ -52,13 +47,11 @@ export class EffectScope { } on() { - this.aliveEffectScope = activeEffectScope activeEffectScope = this } off() { - activeEffectScope = this.aliveEffectScope - delete this.aliveEffectScope + activeEffectScope = this.parent } stop(fromParent?: boolean) {