From cab2d3979518f3c6cc11f39b8d595eaab479eff4 Mon Sep 17 00:00:00 2001 From: webfansplz <308241863@qq.com> Date: Mon, 27 Jun 2022 11:36:49 +0800 Subject: [PATCH 1/4] chore(effectscope): expose `active` property as public type --- packages/reactivity/src/effectScope.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/reactivity/src/effectScope.ts b/packages/reactivity/src/effectScope.ts index f4396e8f3ab..046e5a367e2 100644 --- a/packages/reactivity/src/effectScope.ts +++ b/packages/reactivity/src/effectScope.ts @@ -4,9 +4,6 @@ import { warn } from './warning' let activeEffectScope: EffectScope | undefined export class EffectScope { - /** - * @internal - */ active = true /** * @internal From e8d9463130fe896aa8eab4cd7450c524b4704011 Mon Sep 17 00:00:00 2001 From: webfansplz <308241863@qq.com> Date: Mon, 27 Jun 2022 16:23:52 +0800 Subject: [PATCH 2/4] feat(effectScope): add `active` property getter --- packages/reactivity/__tests__/effectScope.spec.ts | 8 ++++++++ packages/reactivity/src/effectScope.ts | 15 +++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/reactivity/__tests__/effectScope.spec.ts b/packages/reactivity/__tests__/effectScope.spec.ts index af92c97f94c..761f56f841c 100644 --- a/packages/reactivity/__tests__/effectScope.spec.ts +++ b/packages/reactivity/__tests__/effectScope.spec.ts @@ -26,6 +26,14 @@ describe('reactivity/effect/scope', () => { expect(new EffectScope().run(() => 1)).toBe(1) }) + it('should work w/ active property', () => { + const scope = new EffectScope() + scope.run(() => 1) + expect(scope.active).toBe(true) + scope.stop() + expect(scope.active).toBe(false) + }) + it('should collect the effects', () => { const scope = new EffectScope() scope.run(() => { diff --git a/packages/reactivity/src/effectScope.ts b/packages/reactivity/src/effectScope.ts index 046e5a367e2..674570ce14f 100644 --- a/packages/reactivity/src/effectScope.ts +++ b/packages/reactivity/src/effectScope.ts @@ -4,7 +4,10 @@ import { warn } from './warning' let activeEffectScope: EffectScope | undefined export class EffectScope { - active = true + /** + * @internal + */ + private _active = true /** * @internal */ @@ -41,8 +44,12 @@ export class EffectScope { } } + get active() { + return this._active + } + run(fn: () => T): T | undefined { - if (this.active) { + if (this._active) { const currentEffectScope = activeEffectScope try { activeEffectScope = this @@ -72,7 +79,7 @@ export class EffectScope { } stop(fromParent?: boolean) { - if (this.active) { + if (this._active) { let i, l for (i = 0, l = this.effects.length; i < l; i++) { this.effects[i].stop() @@ -94,7 +101,7 @@ export class EffectScope { last.index = this.index! } } - this.active = false + this._active = false } } } From c55472e7387d561cb34443978bdd4de2d327aa11 Mon Sep 17 00:00:00 2001 From: webfansplz <308241863@qq.com> Date: Sat, 5 Nov 2022 11:55:08 +0800 Subject: [PATCH 3/4] chore: update --- .eslintrc.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c0282ebd817..cdbb1dffd91 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,7 +6,7 @@ module.exports = { parserOptions: { sourceType: 'module' }, - plugins: ['jest'], + plugins: ["jest"], rules: { 'no-debugger': 'error', 'no-unused-vars': [ @@ -72,12 +72,7 @@ module.exports = { }, // Node scripts { - files: [ - 'scripts/**', - './*.js', - 'packages/**/index.js', - 'packages/size-check/**' - ], + files: ['scripts/**', './*.js', 'packages/**/index.js', 'packages/size-check/**'], rules: { 'no-restricted-globals': 'off', 'no-restricted-syntax': 'off' From b426df692291bba8384d4a0bbf7d4208587889ea Mon Sep 17 00:00:00 2001 From: webfansplz <308241863@qq.com> Date: Sat, 5 Nov 2022 11:56:06 +0800 Subject: [PATCH 4/4] chore: update