Skip to content

Commit 571ba05

Browse files
committed
refactor: remove namespace usage
1 parent 80a4c84 commit 571ba05

File tree

5 files changed

+345
-330
lines changed

5 files changed

+345
-330
lines changed

packages/reactivity/src/computed.ts

+15-11
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import { ReactiveFlags, TrackOpTypes } from './constants'
33
import { onTrack, setupDirtyLevelHandler } from './debug'
44
import type { DebuggerEvent, DebuggerOptions } from './effect'
55
import {
6-
Dependency,
6+
type Dependency,
77
DirtyLevels,
88
type IComputed,
99
type Link,
10-
Subscriber,
11-
System,
10+
activeSub,
11+
activeTrackId,
12+
endTrack,
13+
link,
14+
propagate,
15+
resolveMaybeDirty,
16+
startTrack,
1217
} from './effect'
1318
import type { Ref } from './ref'
1419
import { warn } from './warning'
@@ -85,7 +90,7 @@ export class ComputedRefImpl<T = any> implements IComputed {
8590
get _dirty(): boolean {
8691
let dirtyLevel = this.dirtyLevel
8792
if (dirtyLevel === DirtyLevels.MaybeDirty) {
88-
Subscriber.resolveMaybeDirty(this)
93+
resolveMaybeDirty(this)
8994
dirtyLevel = this.dirtyLevel
9095
}
9196
return dirtyLevel >= DirtyLevels.Dirty
@@ -123,21 +128,20 @@ export class ComputedRefImpl<T = any> implements IComputed {
123128
if (this._dirty) {
124129
this.update()
125130
}
126-
const activeTrackId = System.activeTrackId
127131
if (activeTrackId !== 0) {
128132
const subsTail = this.subsTail
129133
if (subsTail === undefined || subsTail.trackId !== activeTrackId) {
130134
if (__DEV__) {
131-
onTrack(System.activeSub!, {
135+
onTrack(activeSub!, {
132136
target: this,
133137
type: TrackOpTypes.GET,
134138
key: 'value',
135139
})
136140
}
137-
Dependency.link(this, System.activeSub!)
141+
link(this, activeSub!)
138142
}
139143
} else if (activeEffectScope !== undefined) {
140-
Dependency.link(this, activeEffectScope)
144+
link(this, activeEffectScope)
141145
}
142146
return this._value!
143147
}
@@ -151,19 +155,19 @@ export class ComputedRefImpl<T = any> implements IComputed {
151155
}
152156

153157
update(): void {
154-
const prevSub = Subscriber.startTrack(this)
158+
const prevSub = startTrack(this)
155159
const oldValue = this._value
156160
let newValue: T
157161
try {
158162
newValue = this.fn(oldValue)
159163
} finally {
160-
Subscriber.endTrack(this, prevSub)
164+
endTrack(this, prevSub)
161165
}
162166
if (hasChanged(oldValue, newValue)) {
163167
this._value = newValue
164168
const subs = this.subs
165169
if (subs !== undefined) {
166-
Dependency.propagate(subs)
170+
propagate(subs)
167171
}
168172
}
169173
}

packages/reactivity/src/dep.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { isArray, isIntegerKey, isMap, isSymbol } from '@vue/shared'
22
import { type TrackOpTypes, TriggerOpTypes } from './constants'
33
import { onTrack, triggerEventInfos } from './debug'
4-
import { Dependency, type Link, System, endBatch, startBatch } from './effect'
4+
import {
5+
type Dependency,
6+
type Link,
7+
activeSub,
8+
activeTrackId,
9+
endBatch,
10+
link,
11+
propagate,
12+
startBatch,
13+
} from './effect'
514

615
class Dep implements Dependency {
716
_subs: Link | undefined = undefined
@@ -53,7 +62,6 @@ export const ARRAY_ITERATE_KEY: unique symbol = Symbol(
5362
* @param key - Identifier of the reactive property to track.
5463
*/
5564
export function track(target: object, type: TrackOpTypes, key: unknown): void {
56-
const activeTrackId = System.activeTrackId
5765
if (activeTrackId > 0) {
5866
let depsMap = targetMap.get(target)
5967
if (!depsMap) {
@@ -66,13 +74,13 @@ export function track(target: object, type: TrackOpTypes, key: unknown): void {
6674
const subsTail = dep.subsTail
6775
if (subsTail === undefined || subsTail.trackId !== activeTrackId) {
6876
if (__DEV__) {
69-
onTrack(System.activeSub!, {
77+
onTrack(activeSub!, {
7078
target,
7179
type,
7280
key,
7381
})
7482
}
75-
Dependency.link(dep, System.activeSub!)
83+
link(dep, activeSub!)
7684
}
7785
}
7886
}
@@ -111,7 +119,7 @@ export function trigger(
111119
oldTarget,
112120
})
113121
}
114-
Dependency.propagate(dep.subs)
122+
propagate(dep.subs)
115123
if (__DEV__) {
116124
triggerEventInfos.pop()
117125
}

0 commit comments

Comments
 (0)