Skip to content

Commit 0073a01

Browse files
edison1105yyx990803
authored andcommitted
chore: update test
1 parent d2fd005 commit 0073a01

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

packages/reactivity/__tests__/effectScope.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe('reactivity/effect/scope', () => {
176176

177177
expect('[Vue warn] cannot run an inactive effect scope.').toHaveBeenWarned()
178178

179-
expect(scope.effects.length).toBe(1)
179+
expect(scope.effects.length).toBe(0)
180180

181181
counter.num = 7
182182
expect(dummy).toBe(0)

packages/reactivity/src/effectScope.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,20 @@ export class EffectScope {
123123
for (i = 0, l = effects.length; i < l; i++) {
124124
effects[i].stop()
125125
}
126-
const cleanups = this.cleanups.slice()
127-
for (i = 0, l = cleanups.length; i < l; i++) {
128-
cleanups[i]()
126+
this.effects.length = 0
127+
128+
for (i = 0, l = this.cleanups.length; i < l; i++) {
129+
this.cleanups[i]()
129130
}
131+
this.cleanups.length = 0
132+
130133
if (this.scopes) {
131134
for (i = 0, l = this.scopes.length; i < l; i++) {
132135
this.scopes[i].stop(true)
133136
}
137+
this.scopes.length = 0
134138
}
139+
135140
// nested scope, dereference from parent to avoid memory leaks
136141
if (!this.detached && this.parent && !fromParent) {
137142
// optimized O(1) removal

packages/reactivity/src/watch.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from './effect'
2424
import { isReactive, isShallow } from './reactive'
2525
import { type Ref, isRef } from './ref'
26-
import { getCurrentScope, onScopeDispose } from './effectScope'
26+
import { getCurrentScope } from './effectScope'
2727

2828
// These errors were transferred from `packages/runtime-core/src/errorHandling.ts`
2929
// to @vue/reactivity to allow co-location with the moved base watch logic, hence
@@ -215,10 +215,8 @@ export function watch(
215215
effect.stop()
216216
if (scope && scope.active) {
217217
remove(scope.effects, effect)
218-
remove(scope.cleanups, watchHandle)
219218
}
220219
}
221-
onScopeDispose(watchHandle, true)
222220

223221
if (once && cb) {
224222
const _cb = cb

packages/runtime-core/__tests__/apiWatch.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
} from '@vue/runtime-test'
2626
import {
2727
type DebuggerEvent,
28-
EffectFlags,
2928
ITERATE_KEY,
3029
type Ref,
3130
type ShallowRef,
@@ -1341,7 +1340,7 @@ describe('api: watch', () => {
13411340
await nextTick()
13421341
await nextTick()
13431342

1344-
expect(instance!.scope.effects[0].flags & EffectFlags.ACTIVE).toBeFalsy()
1343+
expect(instance!.scope.effects.length).toBe(0)
13451344
})
13461345

13471346
test('this.$watch should pass `this.proxy` to watch source as the first argument ', () => {

0 commit comments

Comments
 (0)