Skip to content

Commit 425a633

Browse files
committed
refactor: rename getCurrentSub and setCurrentSub to getActiveSub and setActiveSub
1 parent 1d1ef9d commit 425a633

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ let notifyIndex = 0;
5656
let queuedEffectsLength = 0;
5757
let activeSub: ReactiveNode | undefined;
5858

59-
export function getCurrentSub(): ReactiveNode | undefined {
59+
export function getActiveSub(): ReactiveNode | undefined {
6060
return activeSub;
6161
}
6262

63-
export function setCurrentSub(sub: ReactiveNode | undefined) {
63+
export function setActiveSub(sub: ReactiveNode | undefined) {
6464
const prevSub = activeSub;
6565
activeSub = sub;
6666
return prevSub;
@@ -142,7 +142,7 @@ export function effect(fn: () => void): () => void {
142142
if (sub !== undefined) {
143143
link(e, sub, 0);
144144
}
145-
const prevSub = setCurrentSub(e);
145+
const prevSub = setActiveSub(e);
146146
try {
147147
e.fn();
148148
} finally {
@@ -163,7 +163,7 @@ export function effectScope(fn: () => void): () => void {
163163
if (sub !== undefined) {
164164
link(e, sub, 0);
165165
}
166-
const prevSub = setCurrentSub(e);
166+
const prevSub = setActiveSub(e);
167167
try {
168168
fn();
169169
} finally {
@@ -176,7 +176,7 @@ function updateComputed(c: Computed): boolean {
176176
++cycle;
177177
c.depsTail = undefined;
178178
c.flags = 5 as (ReactiveFlags.Mutable | ReactiveFlags.RecursedCheck);
179-
const prevSub = setCurrentSub(c);
179+
const prevSub = setActiveSub(c);
180180
try {
181181
const oldValue = c.value;
182182
return oldValue !== (c.value = c.getter(oldValue));
@@ -219,7 +219,7 @@ function run(e: Effect | EffectScope, flags: ReactiveFlags): void {
219219
++cycle;
220220
e.depsTail = undefined;
221221
e.flags = 6 as (ReactiveFlags.Watching | ReactiveFlags.RecursedCheck);
222-
const prevSub = setCurrentSub(e);
222+
const prevSub = setActiveSub(e);
223223
try {
224224
(e as Effect).fn();
225225
} finally {
@@ -270,7 +270,7 @@ function computedOper<T>(this: Computed<T>): T {
270270
}
271271
} else if (!flags) {
272272
this.flags = 1 satisfies ReactiveFlags.Mutable;
273-
const prevSub = setCurrentSub(this);
273+
const prevSub = setActiveSub(this);
274274
try {
275275
this.value = this.getter();
276276
} finally {

tests/build.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ test('build: cjs', () => {
77
const index = require('../cjs/index.cjs');
88
const system = require('../cjs/system.cjs');
99

10-
expect(typeof index.getCurrentSub).toBe('function');
10+
expect(typeof index.getActiveSub).toBe('function');
1111
expect(typeof system.createReactiveSystem).toBe('function');
1212
});
1313

1414
test('build: esm', async () => {
1515
const index = await import('../esm/index.mjs');
1616
const system = await import('../esm/system.mjs');
1717

18-
expect(typeof index.getCurrentSub).toBe('function');
18+
expect(typeof index.getActiveSub).toBe('function');
1919
expect(typeof system.createReactiveSystem).toBe('function');
2020
});

tests/effect.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from 'vitest';
2-
import { computed, effect, effectScope, endBatch, setCurrentSub, signal, startBatch } from '../src';
2+
import { computed, effect, effectScope, endBatch, setActiveSub, signal, startBatch } from '../src';
33

44
test('should clear subscriptions when untracked by all subscribers', () => {
55
let bRunTimes = 0;
@@ -187,9 +187,9 @@ test('should duplicate subscribers do not affect the notify order', () => {
187187

188188
effect(() => {
189189
order.push('a');
190-
const currentSub = setCurrentSub(undefined);
190+
const currentSub = setActiveSub(undefined);
191191
const isOne = src2() === 1;
192-
setCurrentSub(currentSub);
192+
setActiveSub(currentSub);
193193
if (isOne) {
194194
src1();
195195
}

tests/issue_48.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test } from 'vitest';
2-
import { computed, effect, setCurrentSub, signal } from '../src';
2+
import { computed, effect, setActiveSub, signal } from '../src';
33

44
test('#48', () => {
55
const source = signal(0);
@@ -88,10 +88,10 @@ function reaction<T>(
8888
}
8989

9090
function untracked<T>(callback: () => T): T {
91-
const currentSub = setCurrentSub(undefined);
91+
const currentSub = setActiveSub(undefined);
9292
try {
9393
return callback();
9494
} finally {
95-
setCurrentSub(currentSub);
95+
setActiveSub(currentSub);
9696
}
9797
}

tests/untrack.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { expect, test } from 'vitest';
2-
import { computed, effect, effectScope, setCurrentSub, signal } from '../src';
2+
import { computed, effect, effectScope, setActiveSub, signal } from '../src';
33

44
test('should pause tracking in computed', () => {
55
const src = signal(0);
66

77
let computedTriggerTimes = 0;
88
const c = computed(() => {
99
computedTriggerTimes++;
10-
const currentSub = setCurrentSub(undefined);
10+
const currentSub = setActiveSub(undefined);
1111
const value = src();
12-
setCurrentSub(currentSub);
12+
setActiveSub(currentSub);
1313
return value;
1414
});
1515

@@ -29,9 +29,9 @@ test('should pause tracking in effect', () => {
2929
effect(() => {
3030
effectTriggerTimes++;
3131
if (is()) {
32-
const currentSub = setCurrentSub(undefined);
32+
const currentSub = setActiveSub(undefined);
3333
src();
34-
setCurrentSub(currentSub);
34+
setActiveSub(currentSub);
3535
}
3636
});
3737

@@ -63,9 +63,9 @@ test('should pause tracking in effect scope', () => {
6363
effectScope(() => {
6464
effect(() => {
6565
effectTriggerTimes++;
66-
const currentSub = setCurrentSub(undefined);
66+
const currentSub = setActiveSub(undefined);
6767
src();
68-
setCurrentSub(currentSub);
68+
setActiveSub(currentSub);
6969
});
7070
});
7171

0 commit comments

Comments
 (0)