})
})
+ it('calling on() and off() multiple times inside an active scope should not break currentScope', () => {
+ const parentScope = effectScope()
+ parentScope.run(() => {
+ const childScope = effectScope(true)
+ childScope.on()
+ childScope.on()
+ childScope.off()
+ childScope.off()
+ childScope.off()
+ expect(getCurrentScope()).toBe(parentScope)
+ })
+ })
+
it('should pause/resume EffectScope', async () => {
const counter = reactive({ num: 0 })
const fnSpy = vi.fn(() => counter.num)
* @internal
*/
private _active = true
+ /**
+ * @internal track `on` calls, allow `on` call multiple times
+ */
+ private _on = 0
/**
* @internal
*/
* @internal
*/
on(): void {
- this.prevScope = activeEffectScope
- activeEffectScope = this
+ if (++this._on === 1) {
+ this.prevScope = activeEffectScope
+ activeEffectScope = this
+ }
}
/**
* @internal
*/
off(): void {
- activeEffectScope = this.prevScope
+ if (this._on > 0 && --this._on === 0) {
+ activeEffectScope = this.prevScope
+ this.prevScope = undefined
+ }
}
stop(fromParent?: boolean): void {