Skip to content

Commit a5a566d

Browse files
authored
chore: tidy up (#10705)
* tidy up * tidy up * tidy up * tidy up * remove redundant CLEAN * lint --------- Co-authored-by: Rich Harris <[email protected]>
1 parent b3d0a06 commit a5a566d

File tree

8 files changed

+78
-76
lines changed

8 files changed

+78
-76
lines changed

packages/svelte/src/internal/client/reactivity/deriveds.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,27 @@ import { default_equals, safe_equal } from './equality.js';
1111
*/
1212
/*#__NO_SIDE_EFFECTS__*/
1313
export function derived(fn) {
14-
const is_unowned = current_effect === null;
15-
const flags = is_unowned ? DERIVED | UNOWNED : DERIVED;
16-
const signal = /** @type {import('../types.js').Derived<V>} */ ({
14+
let flags = DERIVED | CLEAN;
15+
if (current_effect === null) flags |= UNOWNED;
16+
17+
/** @type {import('#client').Derived<V>} */
18+
const signal = {
1719
b: current_block,
1820
c: null,
1921
d: null,
2022
e: default_equals,
21-
f: flags | CLEAN,
23+
f: flags,
2224
i: fn,
2325
r: null,
26+
// @ts-expect-error
2427
v: UNINITIALIZED,
2528
w: 0,
2629
x: null,
2730
y: null
28-
});
31+
};
2932

3033
if (DEV) {
31-
// @ts-expect-error
32-
signal.inspect = new Set();
34+
/** @type {import('#client').DerivedDebug} */ (signal).inspect = new Set();
3335
}
3436

3537
if (current_consumer !== null) {
@@ -42,7 +44,7 @@ export function derived(fn) {
4244
/**
4345
* @template V
4446
* @param {() => V} fn
45-
* @returns {import('../types.js').Derived<V>}
47+
* @returns {import('#client').Derived<V>}
4648
*/
4749
/*#__NO_SIDE_EFFECTS__*/
4850
export function derived_safe_equal(fn) {

packages/svelte/src/internal/client/reactivity/effects.js

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
import { DIRTY, MANAGED, RENDER_EFFECT, EFFECT, PRE_EFFECT } from '../constants.js';
1111

1212
/**
13-
* @param {import('../types.js').Reaction} target_signal
14-
* @param {import('../types.js').Reaction} ref_signal
13+
* @param {import('#client').Reaction} target_signal
14+
* @param {import('#client').Reaction} ref_signal
1515
* @returns {void}
1616
*/
1717
export function push_reference(target_signal, ref_signal) {
@@ -24,14 +24,14 @@ export function push_reference(target_signal, ref_signal) {
2424
}
2525

2626
/**
27-
* @param {import('../types.js').EffectType} type
28-
* @param {(() => void | (() => void)) | ((b: import('../types.js').Block) => void | (() => void))} fn
27+
* @param {import('./types.js').EffectType} type
28+
* @param {(() => void | (() => void)) | ((b: import('#client').Block) => void | (() => void))} fn
2929
* @param {boolean} sync
30-
* @param {null | import('../types.js').Block} block
30+
* @param {null | import('#client').Block} block
3131
* @param {boolean} schedule
32-
* @returns {import('../types.js').Effect}
32+
* @returns {import('#client').Effect}
3333
*/
34-
function internal_create_effect(type, fn, sync, block, schedule) {
34+
function create_effect(type, fn, sync, block, schedule) {
3535
/** @type {import('#client').Effect} */
3636
const signal = {
3737
b: block,
@@ -54,13 +54,16 @@ function internal_create_effect(type, fn, sync, block, schedule) {
5454
push_reference(current_effect, signal);
5555
}
5656
}
57+
5758
if (schedule) {
5859
schedule_effect(signal, sync);
5960
}
61+
6062
return signal;
6163
}
6264

6365
/**
66+
* Internal representation of `$effect.active()`
6467
* @returns {boolean}
6568
*/
6669
export function effect_active() {
@@ -70,7 +73,7 @@ export function effect_active() {
7073
/**
7174
* Internal representation of `$effect(...)`
7275
* @param {() => void | (() => void)} fn
73-
* @returns {import('../types.js').Effect}
76+
* @returns {import('#client').Effect}
7477
*/
7578
export function user_effect(fn) {
7679
if (current_effect === null) {
@@ -85,7 +88,7 @@ export function user_effect(fn) {
8588
current_component_context !== null &&
8689
!current_component_context.m;
8790

88-
const effect = internal_create_effect(
91+
const effect = create_effect(
8992
EFFECT,
9093
fn,
9194
false,
@@ -94,9 +97,7 @@ export function user_effect(fn) {
9497
);
9598

9699
if (apply_component_effect_heuristics) {
97-
const context = /** @type {import('../types.js').ComponentContext} */ (
98-
current_component_context
99-
);
100+
const context = /** @type {import('#client').ComponentContext} */ (current_component_context);
100101
(context.e ??= []).push(effect);
101102
}
102103

@@ -117,33 +118,33 @@ export function user_root_effect(fn) {
117118

118119
/**
119120
* @param {() => void | (() => void)} fn
120-
* @returns {import('../types.js').Effect}
121+
* @returns {import('#client').Effect}
121122
*/
122123
export function effect(fn) {
123-
return internal_create_effect(EFFECT, fn, false, current_block, true);
124+
return create_effect(EFFECT, fn, false, current_block, true);
124125
}
125126

126127
/**
127128
* @param {() => void | (() => void)} fn
128-
* @returns {import('../types.js').Effect}
129+
* @returns {import('#client').Effect}
129130
*/
130131
export function managed_effect(fn) {
131-
return internal_create_effect(EFFECT | MANAGED, fn, false, current_block, true);
132+
return create_effect(EFFECT | MANAGED, fn, false, current_block, true);
132133
}
133134

134135
/**
135136
* @param {() => void | (() => void)} fn
136137
* @param {boolean} sync
137-
* @returns {import('../types.js').Effect}
138+
* @returns {import('#client').Effect}
138139
*/
139140
export function managed_pre_effect(fn, sync) {
140-
return internal_create_effect(PRE_EFFECT | MANAGED, fn, sync, current_block, true);
141+
return create_effect(PRE_EFFECT | MANAGED, fn, sync, current_block, true);
141142
}
142143

143144
/**
144145
* Internal representation of `$effect.pre(...)`
145146
* @param {() => void | (() => void)} fn
146-
* @returns {import('../types.js').Effect}
147+
* @returns {import('#client').Effect}
147148
*/
148149
export function pre_effect(fn) {
149150
if (current_effect === null) {
@@ -155,7 +156,7 @@ export function pre_effect(fn) {
155156
);
156157
}
157158
const sync = current_effect !== null && (current_effect.f & RENDER_EFFECT) !== 0;
158-
return internal_create_effect(
159+
return create_effect(
159160
PRE_EFFECT,
160161
() => {
161162
const val = fn();
@@ -173,24 +174,24 @@ export function pre_effect(fn) {
173174
* bindings which are in later effects. However, we don't use a pre_effect directly as we don't want to flush anything.
174175
*
175176
* @param {() => void | (() => void)} fn
176-
* @returns {import('../types.js').Effect}
177+
* @returns {import('#client').Effect}
177178
*/
178179
export function invalidate_effect(fn) {
179-
return internal_create_effect(PRE_EFFECT, fn, true, current_block, true);
180+
return create_effect(PRE_EFFECT, fn, true, current_block, true);
180181
}
181182

182183
/**
183-
* @template {import('../types.js').Block} B
184+
* @template {import('#client').Block} B
184185
* @param {(block: B) => void | (() => void)} fn
185186
* @param {any} block
186187
* @param {any} managed
187188
* @param {any} sync
188-
* @returns {import('../types.js').Effect}
189+
* @returns {import('#client').Effect}
189190
*/
190191
export function render_effect(fn, block = current_block, managed = false, sync = true) {
191192
let flags = RENDER_EFFECT;
192193
if (managed) {
193194
flags |= MANAGED;
194195
}
195-
return internal_create_effect(flags, /** @type {any} */ (fn), sync, block, true);
196+
return create_effect(flags, /** @type {any} */ (fn), sync, block, true);
196197
}

packages/svelte/src/internal/client/reactivity/sources.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ import { CLEAN, DERIVED, DIRTY, MANAGED, SOURCE } from '../constants.js';
2323

2424
/**
2525
* @template V
26-
* @param {V} initial_value
27-
* @returns {import('../types.js').Source<V>}
26+
* @param {V} value
27+
* @returns {import('#client').Source<V>}
2828
*/
2929
/*#__NO_SIDE_EFFECTS__*/
30-
export function source(initial_value) {
30+
export function source(value) {
3131
/** @type {import('#client').Source<V>} */
32-
const signal = {
32+
const source = {
3333
c: null,
3434
e: default_equals,
3535
f: SOURCE | CLEAN,
36-
v: initial_value,
36+
v: value,
3737
w: 0
3838
};
3939

4040
if (DEV) {
41-
/** @type {import('#client').SourceDebug} */ (signal).inspect = new Set();
41+
/** @type {import('#client').SourceDebug<V>} */ (source).inspect = new Set();
4242
}
4343

44-
return signal;
44+
return source;
4545
}
4646

4747
/**
4848
* @template V
4949
* @param {V} initial_value
50-
* @returns {import('../types.js').Source<V>}
50+
* @returns {import('#client').Source<V>}
5151
*/
5252
/*#__NO_SIDE_EFFECTS__*/
5353
export function mutable_source(initial_value) {
@@ -65,7 +65,7 @@ export function mutable_source(initial_value) {
6565

6666
/**
6767
* @template V
68-
* @param {import('./types.js').Source<V>} signal
68+
* @param {import('#client').Source<V>} signal
6969
* @param {V} value
7070
* @returns {void}
7171
*/
@@ -75,7 +75,7 @@ export function set_sync(signal, value) {
7575

7676
/**
7777
* @template V
78-
* @param {import('./types.js').Value<V>} source
78+
* @param {import('#client').Value<V>} source
7979
* @param {V} value
8080
*/
8181
export function mutate(source, value) {
@@ -88,7 +88,7 @@ export function mutate(source, value) {
8888

8989
/**
9090
* @template V
91-
* @param {import('./types.js').Source<V>} signal
91+
* @param {import('#client').Source<V>} signal
9292
* @param {V} value
9393
* @returns {V}
9494
*/
@@ -150,9 +150,9 @@ export function set(signal, value) {
150150
// @ts-expect-error
151151
if (DEV && signal.inspect) {
152152
if (is_batching_effect) {
153-
set_last_inspected_signal(/** @type {import('./types.js').ValueDebug} */ (signal));
153+
set_last_inspected_signal(/** @type {import('#client').ValueDebug} */ (signal));
154154
} else {
155-
for (const fn of /** @type {import('./types.js').ValueDebug} */ (signal).inspect) fn();
155+
for (const fn of /** @type {import('#client').ValueDebug} */ (signal).inspect) fn();
156156
}
157157
}
158158
}

packages/svelte/src/internal/client/reactivity/store.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { mutable_source, set } from './sources.js';
1010
* signal that will be updated when the store is. The store references container is needed to
1111
* track reassignments to stores and to track the correct component context.
1212
* @template V
13-
* @param {import('../types.js').Store<V> | null | undefined} store
13+
* @param {import('#client').Store<V> | null | undefined} store
1414
* @param {string} store_name
15-
* @param {import('../types.js').StoreReferencesContainer} stores
15+
* @param {import('#client').StoreReferencesContainer} stores
1616
* @returns {V}
1717
*/
1818
export function store_get(store, store_name, stores) {
19-
/** @type {import('../types.js').StoreReferencesContainer[''] | undefined} */
19+
/** @type {import('#client').StoreReferencesContainer[''] | undefined} */
2020
let entry = stores[store_name];
2121
const is_new = entry === undefined;
2222

@@ -29,8 +29,8 @@ export function store_get(store, store_name, stores) {
2929
};
3030
// TODO: can we remove this code? it was refactored out when we split up source/comptued signals
3131
// push_destroy_fn(entry.value, () => {
32-
// /** @type {import('../types.js').StoreReferencesContainer['']} */ (entry).last_value =
33-
// /** @type {import('../types.js').StoreReferencesContainer['']} */ (entry).value.value;
32+
// /** @type {import('#client').StoreReferencesContainer['']} */ (entry).last_value =
33+
// /** @type {import('#client').StoreReferencesContainer['']} */ (entry).value.value;
3434
// });
3535
stores[store_name] = entry;
3636
}
@@ -49,8 +49,8 @@ export function store_get(store, store_name, stores) {
4949

5050
/**
5151
* @template V
52-
* @param {import('../types.js').Store<V> | null | undefined} store
53-
* @param {import('../types.js').Source<V>} source
52+
* @param {import('#client').Store<V> | null | undefined} store
53+
* @param {import('#client').Source<V>} source
5454
*/
5555
function connect_store_to_signal(store, source) {
5656
if (store == null) {
@@ -70,7 +70,7 @@ function connect_store_to_signal(store, source) {
7070
/**
7171
* Sets the new value of a store and returns that value.
7272
* @template V
73-
* @param {import('../types.js').Store<V>} store
73+
* @param {import('#client').Store<V>} store
7474
* @param {V} value
7575
* @returns {V}
7676
*/
@@ -81,7 +81,7 @@ export function store_set(store, value) {
8181

8282
/**
8383
* Unsubscribes from all auto-subscribed stores on destroy
84-
* @param {import('../types.js').StoreReferencesContainer} stores
84+
* @param {import('#client').StoreReferencesContainer} stores
8585
*/
8686
export function unsubscribe_on_destroy(stores) {
8787
on_destroy(() => {
@@ -97,7 +97,7 @@ export function unsubscribe_on_destroy(stores) {
9797

9898
/**
9999
* Updates a store with a new value.
100-
* @param {import('../types.js').Store<V>} store the store to update
100+
* @param {import('#client').Store<V>} store the store to update
101101
* @param {any} expression the expression that mutates the store
102102
* @param {V} new_value the new store value
103103
* @template V
@@ -110,18 +110,18 @@ export function mutate_store(store, expression, new_value) {
110110
/**
111111
* @template V
112112
* @param {unknown} val
113-
* @returns {val is import('../types.js').Store<V>}
113+
* @returns {val is import('#client').Store<V>}
114114
*/
115115
export function is_store(val) {
116116
return (
117117
typeof val === 'object' &&
118118
val !== null &&
119-
typeof (/** @type {import('../types.js').Store<V>} */ (val).subscribe) === 'function'
119+
typeof (/** @type {import('#client').Store<V>} */ (val).subscribe) === 'function'
120120
);
121121
}
122122

123123
/**
124-
* @param {import('../types.js').Store<number>} store
124+
* @param {import('#client').Store<number>} store
125125
* @param {number} store_value
126126
* @param {1 | -1} [d]
127127
* @returns {number}
@@ -132,7 +132,7 @@ export function update_store(store, store_value, d = 1) {
132132
}
133133

134134
/**
135-
* @param {import('../types.js').Store<number>} store
135+
* @param {import('#client').Store<number>} store
136136
* @param {number} store_value
137137
* @param {1 | -1} [d]
138138
* @returns {number}

packages/svelte/src/internal/client/reactivity/types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ export type Effect = {
7878

7979
export type Reaction = Derived | Effect;
8080

81-
export type Signal<V = unknown> = Source<V> | Reaction;
82-
8381
export type MaybeSignal<T = unknown> = T | Source<T>;
8482

8583
export type UnwrappedSignal<T> = T extends Value<infer U> ? U : T;
8684

8785
export type Value<V = unknown> = Source<V> | Derived<V>;
8886

8987
export type ValueDebug<V = unknown> = SourceDebug<V> | DerivedDebug<V>;
88+
89+
export type Signal = Source | Derived | Effect;

0 commit comments

Comments
 (0)