diff --git a/packages/reactivity/__tests__/effect.spec.ts b/packages/reactivity/__tests__/effect.spec.ts index 3b3f583f066..65e913e4835 100644 --- a/packages/reactivity/__tests__/effect.spec.ts +++ b/packages/reactivity/__tests__/effect.spec.ts @@ -1089,11 +1089,11 @@ describe('reactivity/effect', () => { expect(obj.foo).toBe(2) runner.effect.resume() - expect(fnSpy).toHaveBeenCalledTimes(1) + expect(fnSpy).toHaveBeenCalledTimes(2) expect(obj.foo).toBe(2) obj.foo++ - expect(fnSpy).toHaveBeenCalledTimes(2) + expect(fnSpy).toHaveBeenCalledTimes(3) expect(obj.foo).toBe(3) }) @@ -1110,12 +1110,12 @@ describe('reactivity/effect', () => { expect(fnSpy).toHaveBeenCalledTimes(1) expect(obj.foo).toBe(2) - runner.effect.resume(true) - expect(fnSpy).toHaveBeenCalledTimes(2) - expect(obj.foo).toBe(2) - obj.foo++ - expect(fnSpy).toHaveBeenCalledTimes(3) + expect(fnSpy).toHaveBeenCalledTimes(1) + expect(obj.foo).toBe(3) + + runner.effect.resume() + expect(fnSpy).toHaveBeenCalledTimes(2) expect(obj.foo).toBe(3) }) }) diff --git a/packages/reactivity/__tests__/effectScope.spec.ts b/packages/reactivity/__tests__/effectScope.spec.ts index 94c2b12c6f9..f45b28a2c84 100644 --- a/packages/reactivity/__tests__/effectScope.spec.ts +++ b/packages/reactivity/__tests__/effectScope.spec.ts @@ -316,39 +316,11 @@ describe('reactivity/effect/scope', () => { await nextTick() expect(fnSpy).toHaveBeenCalledTimes(2) - scope.resume() - await nextTick() - expect(fnSpy).toHaveBeenCalledTimes(2) - - counter.num++ - await nextTick() - expect(fnSpy).toHaveBeenCalledTimes(3) - }) - - it('should execute all saved run methods in effects immediately upon resuming', async () => { - const counter = reactive({ num: 0 }) - const fnSpy = vi.fn(() => counter.num) - const scope = new EffectScope() - scope.run(() => { - effect(fnSpy) - }) - - expect(fnSpy).toHaveBeenCalledTimes(1) - counter.num++ await nextTick() expect(fnSpy).toHaveBeenCalledTimes(2) - scope.pause() - counter.num++ - await nextTick() - expect(fnSpy).toHaveBeenCalledTimes(2) - - scope.resume(true) + scope.resume() expect(fnSpy).toHaveBeenCalledTimes(3) - - counter.num++ - await nextTick() - expect(fnSpy).toHaveBeenCalledTimes(4) }) }) diff --git a/packages/reactivity/src/effect.ts b/packages/reactivity/src/effect.ts index ed893bbd99a..f7e4126bdf7 100644 --- a/packages/reactivity/src/effect.ts +++ b/packages/reactivity/src/effect.ts @@ -103,18 +103,15 @@ export class ReactiveEffect { /** * Resumes the execution of the reactive effect. - * @param {boolean} immediate - If true, executes the saved run method immediately upon resuming. */ - resume(immediate: boolean = false) { + resume() { if (!this._isStopped) { this.active = true if (pausedQueueEffects.has(this)) { pausedQueueEffects.delete(this) queueEffectSchedulers.push(this.scheduler!) - if (immediate) { - pauseScheduling() - resetScheduling() - } + pauseScheduling() + resetScheduling() } } } diff --git a/packages/reactivity/src/effectScope.ts b/packages/reactivity/src/effectScope.ts index ace77afbdff..db621394835 100644 --- a/packages/reactivity/src/effectScope.ts +++ b/packages/reactivity/src/effectScope.ts @@ -75,11 +75,11 @@ export class EffectScope { this._isPaused = false if (this.scopes) { for (let i = 0, l = this.scopes.length; i < l; i++) { - this.scopes[i].resume(immediate) + this.scopes[i].resume() } } for (let i = 0, l = this.effects.length; i < l; i++) { - this.effects[i].resume(immediate) + this.effects[i].resume() } } } diff --git a/packages/runtime-core/__tests__/apiWatch.spec.ts b/packages/runtime-core/__tests__/apiWatch.spec.ts index b66e6651e73..872b623a12f 100644 --- a/packages/runtime-core/__tests__/apiWatch.spec.ts +++ b/packages/runtime-core/__tests__/apiWatch.spec.ts @@ -1312,7 +1312,7 @@ describe('api: watch', () => { expect(cb).toHaveBeenCalledTimes(3) expect(cb).toHaveBeenLastCalledWith(4, 3, expect.any(Function)) - resume(true) + resume() await nextTick() expect(cb).toHaveBeenCalledTimes(4) expect(cb).toHaveBeenLastCalledWith(5, 4, expect.any(Function)) diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index eec03736313..83b84dc4bca 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -82,7 +82,7 @@ export type WatchStopHandle = () => void export interface WatchHandle extends WatchStopHandle { pause: () => void - resume: (immediate?: boolean) => void + resume: () => void stop: () => void } @@ -393,8 +393,8 @@ function doWatch( } const watchHandle: WatchHandle = () => unwatch() - watchHandle.pause = () => effect.pause() - watchHandle.resume = immediate => effect.resume(immediate) + watchHandle.pause = effect.pause.bind(effect) + watchHandle.resume = effect.resume.bind(effect) watchHandle.stop = unwatch if (__DEV__) {