@@ -46,7 +46,7 @@ let current_queued_tasks = [];
46
46
let flush_count = 0 ;
47
47
// Handle signal reactivity tree dependencies and consumer
48
48
49
- /** @type {null | import('./types.js').Signal } */
49
+ /** @type {null | import('./types.js').ComputationSignal } */
50
50
let current_consumer = null ;
51
51
52
52
/** @type {null | import('./types.js').EffectSignal } */
@@ -133,14 +133,31 @@ function default_equals(a, b) {
133
133
return a === b ;
134
134
}
135
135
136
+ /**
137
+ * @template V
138
+ * @param {import('./types.js').SignalFlags } flags
139
+ * @param {V } value
140
+ * @returns {import('./types.js').SourceSignal<V> }
141
+ */
142
+ function create_source_signal ( flags , value ) {
143
+ return {
144
+ consumers : null ,
145
+ // We can remove this if we get rid of beforeUpdate/afterUpdate
146
+ context : null ,
147
+ equals : null ,
148
+ flags,
149
+ value
150
+ } ;
151
+ }
152
+
136
153
/**
137
154
* @template V
138
155
* @param {import('./types.js').SignalFlags } flags
139
156
* @param {V } value
140
157
* @param {import('./types.js').Block | null } block
141
- * @returns {import('./types.js').Signal <V> }
158
+ * @returns {import('./types.js').ComputationSignal <V> }
142
159
*/
143
- function create_signal_object ( flags , value , block ) {
160
+ function create_computation_signal ( flags , value , block ) {
144
161
return {
145
162
block,
146
163
consumers : null ,
@@ -156,8 +173,8 @@ function create_signal_object(flags, value, block) {
156
173
}
157
174
158
175
/**
159
- * @param {import('./types.js').Signal } target_signal
160
- * @param {import('./types.js').Signal } ref_signal
176
+ * @param {import('./types.js').ComputationSignal } target_signal
177
+ * @param {import('./types.js').ComputationSignal } ref_signal
161
178
* @returns {void }
162
179
*/
163
180
function push_reference ( target_signal , ref_signal ) {
@@ -180,7 +197,7 @@ function is_signal_dirty(signal) {
180
197
return true ;
181
198
}
182
199
if ( ( flags & MAYBE_DIRTY ) !== 0 ) {
183
- const dependencies = signal . dependencies ;
200
+ const dependencies = /** @type { import('./types.js').ComputationSignal<V> } **/ ( signal ) . dependencies ;
184
201
if ( dependencies !== null ) {
185
202
const length = dependencies . length ;
186
203
let i ;
@@ -195,7 +212,7 @@ function is_signal_dirty(signal) {
195
212
// The flags can be marked as dirty from the above is_signal_dirty call.
196
213
if ( ( dependency . flags & DIRTY ) !== 0 ) {
197
214
if ( ( dep_flags & DERIVED ) !== 0 ) {
198
- update_derived ( dependency , true ) ;
215
+ update_derived ( /** @type { import('./types.js').ComputationSignal<V> } **/ ( dependency ) , true ) ;
199
216
// Might have been mutated from above get.
200
217
if ( ( signal . flags & DIRTY ) !== 0 ) {
201
218
return true ;
@@ -212,7 +229,7 @@ function is_signal_dirty(signal) {
212
229
213
230
/**
214
231
* @template V
215
- * @param {import('./types.js').Signal <V> } signal
232
+ * @param {import('./types.js').ComputationSignal <V> } signal
216
233
* @returns {V }
217
234
*/
218
235
function execute_signal_fn ( signal ) {
@@ -247,7 +264,7 @@ function execute_signal_fn(signal) {
247
264
} else {
248
265
res = /** @type {() => V } */ ( init ) ( ) ;
249
266
}
250
- let dependencies = signal . dependencies ;
267
+ let dependencies = /** @type { import('./types.js').Signal<unknown>[] } **/ ( signal . dependencies ) ;
251
268
252
269
if ( current_dependencies !== null ) {
253
270
let i ;
@@ -259,7 +276,7 @@ function execute_signal_fn(signal) {
259
276
dependencies [ current_dependencies_index + i ] = current_dependencies [ i ] ;
260
277
}
261
278
} else {
262
- signal . dependencies = dependencies = current_dependencies ;
279
+ signal . dependencies = /** @type { import('./types.js').Signal<V>[] } **/ ( dependencies = current_dependencies ) ;
263
280
}
264
281
265
282
if ( ! current_skip_consumer ) {
@@ -291,7 +308,7 @@ function execute_signal_fn(signal) {
291
308
292
309
/**
293
310
* @template V
294
- * @param {import('./types.js').Signal <V> } signal
311
+ * @param {import('./types.js').ComputationSignal <V> } signal
295
312
* @param {number } start_index
296
313
* @param {boolean } remove_unowned
297
314
* @returns {void }
@@ -316,15 +333,19 @@ function remove_consumer(signal, start_index, remove_unowned) {
316
333
}
317
334
}
318
335
if ( remove_unowned && consumers_length === 0 && ( dependency . flags & UNOWNED ) !== 0 ) {
319
- remove_consumer ( dependency , 0 , true ) ;
336
+ remove_consumer (
337
+ /** @type {import('./types.js').ComputationSignal<V> } **/ ( dependency ) ,
338
+ 0 ,
339
+ true
340
+ ) ;
320
341
}
321
342
}
322
343
}
323
344
}
324
345
325
346
/**
326
347
* @template V
327
- * @param {import('./types.js').Signal <V> } signal
348
+ * @param {import('./types.js').ComputationSignal <V> } signal
328
349
* @returns {void }
329
350
*/
330
351
function destroy_references ( signal ) {
@@ -575,7 +596,7 @@ export async function tick() {
575
596
576
597
/**
577
598
* @template V
578
- * @param {import('./types.js').Signal <V> } signal
599
+ * @param {import('./types.js').ComputationSignal <V> } signal
579
600
* @param {boolean } force_schedule
580
601
* @returns {void }
581
602
*/
@@ -615,10 +636,11 @@ export function store_get(store, store_name, stores) {
615
636
value : source ( UNINITIALIZED ) ,
616
637
unsubscribe : EMPTY_FUNC
617
638
} ;
618
- push_destroy_fn ( entry . value , ( ) => {
619
- /** @type {import('./types.js').StoreReferencesContainer[''] } */ ( entry ) . last_value =
620
- /** @type {import('./types.js').StoreReferencesContainer[''] } */ ( entry ) . value . value ;
621
- } ) ;
639
+ // TODO: can we remove this code? it was refactored out when we split up source/comptued signals
640
+ // push_destroy_fn(entry.value, () => {
641
+ // /** @type {import('./types.js').StoreReferencesContainer[''] } */ (entry).last_value =
642
+ // /** @type {import('./types.js').StoreReferencesContainer[''] } */ (entry).value.value;
643
+ // });
622
644
stores [ store_name ] = entry ;
623
645
}
624
646
@@ -676,7 +698,8 @@ export function unsubscribe_on_destroy(stores) {
676
698
for ( store_name in stores ) {
677
699
const ref = stores [ store_name ] ;
678
700
ref . unsubscribe ( ) ;
679
- destroy_signal ( ref . value ) ;
701
+ // TODO: can we remove this code? it was refactored out when we split up source/comptued signals
702
+ // destroy_signal(ref.value);
680
703
}
681
704
} ) ;
682
705
}
@@ -740,7 +763,7 @@ export function get(signal) {
740
763
}
741
764
742
765
if ( ( flags & DERIVED ) !== 0 && is_signal_dirty ( signal ) ) {
743
- update_derived ( signal , false ) ;
766
+ update_derived ( /** @type { import('./types.js').ComputationSignal<V> } **/ ( signal ) , false ) ;
744
767
}
745
768
return signal . value ;
746
769
}
@@ -845,7 +868,7 @@ export function mutate_store(store, expression, new_value) {
845
868
}
846
869
847
870
/**
848
- * @param {import('./types.js').Signal } signal
871
+ * @param {import('./types.js').ComputationSignal } signal
849
872
* @param {boolean } inert
850
873
* @returns {void }
851
874
*/
@@ -969,12 +992,13 @@ export function set_signal_value(signal, value) {
969
992
970
993
/**
971
994
* @template V
972
- * @param {import('./types.js').Signal <V> } signal
995
+ * @param {import('./types.js').ComputationSignal <V> } signal
973
996
* @returns {void }
974
997
*/
975
998
export function destroy_signal ( signal ) {
976
999
const teardown = /** @type {null | (() => void) } */ ( signal . value ) ;
977
1000
const destroy = signal . destroy ;
1001
+ const flags = signal . flags ;
978
1002
destroy_references ( signal ) ;
979
1003
remove_consumer ( signal , 0 , true ) ;
980
1004
signal . init = null ;
@@ -1005,14 +1029,14 @@ export function destroy_signal(signal) {
1005
1029
* @template V
1006
1030
* @param {() => V } init
1007
1031
* @param {import('./types.js').EqualsFunctions } [equals]
1008
- * @returns {import('./types.js').Signal <V> }
1032
+ * @returns {import('./types.js').ComputationSignal <V> }
1009
1033
*/
1010
1034
/*#__NO_SIDE_EFFECTS__*/
1011
1035
export function derived ( init , equals ) {
1012
1036
const is_unowned = current_effect === null ;
1013
1037
const flags = is_unowned ? DERIVED | UNOWNED : DERIVED ;
1014
- const signal = /** @type {import('./types.js').Signal <V> } */ (
1015
- create_signal_object ( flags | CLEAN , UNINITIALIZED , current_block )
1038
+ const signal = /** @type {import('./types.js').ComputationSignal <V> } */ (
1039
+ create_computation_signal ( flags | CLEAN , UNINITIALIZED , current_block )
1016
1040
) ;
1017
1041
signal . init = init ;
1018
1042
signal . context = current_component_context ;
@@ -1027,11 +1051,11 @@ export function derived(init, equals) {
1027
1051
* @template V
1028
1052
* @param {V } initial_value
1029
1053
* @param {import('./types.js').EqualsFunctions<V> } [equals]
1030
- * @returns {import('./types.js').Signal <V> }
1054
+ * @returns {import('./types.js').SourceSignal <V> }
1031
1055
*/
1032
1056
/*#__NO_SIDE_EFFECTS__*/
1033
1057
export function source ( initial_value , equals ) {
1034
- const source = create_signal_object ( SOURCE | CLEAN , initial_value , null ) ;
1058
+ const source = create_source_signal ( SOURCE | CLEAN , initial_value ) ;
1035
1059
source . context = current_component_context ;
1036
1060
source . equals = get_equals_method ( equals ) ;
1037
1061
return source ;
@@ -1079,7 +1103,7 @@ export function untrack(fn) {
1079
1103
* @returns {import('./types.js').EffectSignal }
1080
1104
*/
1081
1105
function internal_create_effect ( type , init , sync , block , schedule ) {
1082
- const signal = create_signal_object ( type | DIRTY , null , block ) ;
1106
+ const signal = create_computation_signal ( type | DIRTY , null , block ) ;
1083
1107
signal . init = init ;
1084
1108
signal . context = current_component_context ;
1085
1109
if ( schedule ) {
@@ -1210,7 +1234,7 @@ export function managed_render_effect(init, block = current_block, sync = true)
1210
1234
1211
1235
/**
1212
1236
* @template V
1213
- * @param {import('./types.js').Signal <V> } signal
1237
+ * @param {import('./types.js').ComputationSignal <V> } signal
1214
1238
* @param {() => void } destroy_fn
1215
1239
* @returns {void }
1216
1240
*/
0 commit comments