From 81a6708739164e015affcc57bb22e820bfeee7d3 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 28 Jan 2022 21:02:09 +0800 Subject: [PATCH] chore: simplify effectScope --- packages/reactivity/src/effectScope.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/reactivity/src/effectScope.ts b/packages/reactivity/src/effectScope.ts index 7c3dbc989..fcacab6e3 100644 --- a/packages/reactivity/src/effectScope.ts +++ b/packages/reactivity/src/effectScope.ts @@ -29,10 +29,10 @@ export class EffectScope { run(fn: () => T): T | undefined { if (this.active) { try { - this.on() + activeEffectScope = this return fn() } finally { - this.off() + activeEffectScope = this.parent } } else if (__DEV__) { warn(`cannot run an inactive effect scope.`) @@ -40,15 +40,11 @@ export class EffectScope { } on() { - if (this.active) { - activeEffectScope = this - } + activeEffectScope = this } off() { - if (this.active) { - activeEffectScope = this.parent - } + activeEffectScope = this.parent } stop(fromParent?: boolean) {