Skip to content

Commit 6f6b8b9

Browse files
committed
refactor: remove namespaces
1 parent 6a2e9ec commit 6f6b8b9

File tree

5 files changed

+306
-318
lines changed

5 files changed

+306
-318
lines changed

src/computed.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dependency, DirtyLevels, IComputed, Link, Subscriber, System } from './system.js';
1+
import { checkDirty, DirtyLevels, endTrack, IComputed, link, Link, propagate, startTrack, System } from './system.js';
22

33
export interface ISignal<T = any> {
44
get(): T;
@@ -29,11 +29,11 @@ export class Computed<T = any> implements IComputed {
2929
get(): T {
3030
const dirtyLevel = this.dirtyLevel;
3131
if (dirtyLevel > DirtyLevels.None) {
32-
if (dirtyLevel === DirtyLevels.Dirty || Subscriber.checkDirty(this.deps!)) {
32+
if (dirtyLevel === DirtyLevels.Dirty || checkDirty(this.deps!)) {
3333
if (this.update()) {
3434
const subs = this.subs;
3535
if (subs !== undefined) {
36-
Dependency.propagate(subs);
36+
propagate(subs);
3737
}
3838
}
3939
} else {
@@ -44,20 +44,20 @@ export class Computed<T = any> implements IComputed {
4444
if (activeTrackId !== 0) {
4545
const subsTail = this.subsTail;
4646
if (subsTail === undefined || subsTail.trackId !== activeTrackId) {
47-
Dependency.link(this, System.activeSub!);
47+
link(this, System.activeSub!);
4848
}
4949
}
5050
return this.cachedValue!;
5151
}
5252

5353
update(): boolean {
54-
const prevSub = Subscriber.startTrack(this);
54+
const prevSub = startTrack(this);
5555
const oldValue = this.cachedValue;
5656
let newValue: T;
5757
try {
5858
newValue = this.getter(oldValue);
5959
} finally {
60-
Subscriber.endTrack(this, prevSub);
60+
endTrack(this, prevSub);
6161
}
6262
if (oldValue !== newValue) {
6363
this.cachedValue = newValue;

src/effect.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { activeEffectScope } from './effectScope.js';
2-
import { Dependency, DirtyLevels, IEffect, Link, Subscriber, System } from './system.js';
2+
import { checkDirty, clearTrack, Dependency, DirtyLevels, endTrack, IEffect, link, Link, startTrack, System } from './system.js';
33

44
export function effect(fn: () => void): Effect<void> {
55
const e = new Effect(fn);
@@ -26,13 +26,13 @@ export class Effect<T = any> implements IEffect, Dependency {
2626
) {
2727
const activeTrackId = System.activeTrackId;
2828
if (activeTrackId !== 0) {
29-
Dependency.link(this, System.activeSub!);
29+
link(this, System.activeSub!);
3030
return;
3131
}
3232
if (activeEffectScope !== undefined) {
3333
const subsTail = this.subsTail;
3434
if (subsTail === undefined || subsTail.trackId !== activeEffectScope.trackId) {
35-
Dependency.link(this, activeEffectScope);
35+
link(this, activeEffectScope);
3636
}
3737
}
3838
}
@@ -41,7 +41,7 @@ export class Effect<T = any> implements IEffect, Dependency {
4141
let dirtyLevel = this.dirtyLevel;
4242
if (dirtyLevel > DirtyLevels.None) {
4343
if (dirtyLevel === DirtyLevels.MaybeDirty) {
44-
dirtyLevel = Subscriber.checkDirty(this.deps!)
44+
dirtyLevel = checkDirty(this.deps!)
4545
? DirtyLevels.Dirty
4646
: DirtyLevels.SideEffectsOnly;
4747
}
@@ -64,17 +64,17 @@ export class Effect<T = any> implements IEffect, Dependency {
6464
}
6565

6666
run(): T {
67-
const prevSub = Subscriber.startTrack(this);
67+
const prevSub = startTrack(this);
6868
try {
6969
return this.fn();
7070
} finally {
71-
Subscriber.endTrack(this, prevSub);
71+
endTrack(this, prevSub);
7272
}
7373
}
7474

7575
stop(): void {
7676
if (this.deps !== undefined) {
77-
Subscriber.clearTrack(this.deps);
77+
clearTrack(this.deps);
7878
this.deps = undefined;
7979
this.depsTail = undefined;
8080
}

src/effectScope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DirtyLevels, Link, Subscriber, System } from './system.js';
1+
import { clearTrack, DirtyLevels, Link, Subscriber, System } from './system.js';
22

33
export let activeEffectScope: EffectScope | undefined = undefined;
44

@@ -42,7 +42,7 @@ export class EffectScope implements Subscriber {
4242

4343
stop(): void {
4444
if (this.deps !== undefined) {
45-
Subscriber.clearTrack(this.deps);
45+
clearTrack(this.deps);
4646
this.deps = undefined;
4747
this.depsTail = undefined;
4848
}

src/signal.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ISignal } from './computed.js';
2-
import { Dependency, endBatch, Link, startBatch, System } from './system.js';
2+
import { Dependency, endBatch, link, Link, propagate, startBatch, System } from './system.js';
33

44
export interface IWritableSignal<T = any> extends ISignal<T> {
55
set(value: T): void;
@@ -25,7 +25,7 @@ export class Signal<T = any> implements Dependency {
2525
if (activeTrackId !== 0) {
2626
const subsTail = this.subsTail;
2727
if (subsTail === undefined || subsTail.trackId !== activeTrackId) {
28-
Dependency.link(this, System.activeSub!);
28+
link(this, System.activeSub!);
2929
}
3030
}
3131
return this.currentValue!;
@@ -36,7 +36,7 @@ export class Signal<T = any> implements Dependency {
3636
const subs = this.subs;
3737
if (subs !== undefined) {
3838
startBatch();
39-
Dependency.propagate(subs);
39+
propagate(subs);
4040
endBatch();
4141
}
4242
}

0 commit comments

Comments
 (0)