Skip to content

Commit aa81b75

Browse files
committed
Fix more tests [skip ci]
1 parent 78a160b commit aa81b75

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

packages/reactivity/__tests__/effectScope.spec.ts

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

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

190-
expect(getDepCount(scope)).toBe(0)
190+
expect(getDepCount(scope)).toBe(1)
191191

192192
counter.num = 7
193193
expect(dummy).toBe(0)

packages/reactivity/src/effectScope.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export class EffectScope implements Subscriber {
7070
if (this.pauseLevel >= PauseLevels.Paused) {
7171
this.pauseLevel = PauseLevels.None
7272
if (this.scopes) {
73-
for (const scope of this.scopes) {
74-
scope.resume()
73+
for (let i = 0, l = this.scopes.length; i < l; i++) {
74+
this.scopes[i].resume()
7575
}
7676
}
7777
let dep = this.deps
@@ -122,17 +122,13 @@ export class EffectScope implements Subscriber {
122122
;(dep.dep as ReactiveEffect).stop()
123123
dep = dep.nextDep
124124
}
125-
if (this.deps !== undefined) {
126-
Subscriber.clearTrack(this.deps)
127-
this.deps = undefined
128-
this.depsTail = undefined
129-
}
130-
for (const cleanup of this.cleanups) {
131-
cleanup()
125+
let i, l
126+
for (i = 0, l = this.cleanups.length; i < l; i++) {
127+
this.cleanups[i]()
132128
}
133129
if (this.scopes) {
134-
for (const scope of this.scopes) {
135-
scope.stop(true)
130+
for (i = 0, l = this.scopes.length; i < l; i++) {
131+
this.scopes[i].stop(true)
136132
}
137133
}
138134
// nested scope, dereference from parent to avoid memory leaks

packages/reactivity/src/ref.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ class RefImpl<T = any> implements Dependency {
124124
this[ReactiveFlags.IS_SHALLOW] = isShallow
125125
}
126126

127+
get dep() {
128+
return this
129+
}
130+
127131
get value() {
128-
track(this)
132+
trackRef(this)
129133
return this._value
130134
}
131135

@@ -183,14 +187,14 @@ class RefImpl<T = any> implements Dependency {
183187
*/
184188
export function triggerRef(ref: Ref): void {
185189
// ref may be an instance of ObjectRefImpl
186-
if ((ref as unknown as Dependency).subs !== undefined) {
190+
if ((ref as unknown as RefImpl).dep?.subs !== undefined) {
187191
startBatch()
188-
Dependency.propagate((ref as unknown as Dependency).subs!)
192+
Dependency.propagate((ref as unknown as RefImpl).dep!.subs!)
189193
endBatch()
190194
}
191195
}
192196

193-
function track(dep: Dependency) {
197+
function trackRef(dep: Dependency) {
194198
const activeTrackId = System.activeTrackId
195199
if (activeTrackId !== 0 && dep.subsTail?.trackId !== activeTrackId) {
196200
if (__DEV__) {
@@ -306,13 +310,17 @@ class CustomRefImpl<T> implements Dependency {
306310

307311
constructor(factory: CustomRefFactory<T>) {
308312
const { get, set } = factory(
309-
() => track(this),
313+
() => trackRef(this),
310314
() => triggerRef(this as unknown as Ref),
311315
)
312316
this._get = get
313317
this._set = set
314318
}
315319

320+
get dep() {
321+
return this
322+
}
323+
316324
get value() {
317325
return (this._value = this._get())
318326
}
@@ -356,7 +364,7 @@ export function toRefs<T extends object>(object: T): ToRefs<T> {
356364
return ret
357365
}
358366

359-
class ObjectRefImpl<T extends object, K extends keyof T> implements Dependency {
367+
class ObjectRefImpl<T extends object, K extends keyof T> {
360368
// Dependency
361369
subs = undefined
362370
subsTail = undefined

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
type ComputedRefImpl,
33
type ReactiveEffectRunner,
4-
effect
4+
effect,
55
} from '@vue/reactivity'
66
import {
77
type ComponentInternalInstance,
@@ -454,7 +454,7 @@ describe('SFC <script setup> helpers', () => {
454454

455455
await ready
456456
expect(e!.effect.active).toBeTruthy()
457-
expect(c!.trackId > 0).toBeTruthy()
457+
expect(c!.trackId > 0).toBeFalsy()
458458

459459
app.unmount()
460460
expect(e!.effect.active).toBeFalsy()

0 commit comments

Comments
 (0)