@@ -191,9 +191,36 @@ function create_source_signal(flags, value) {
191
191
* @param {import('./types.js').SignalFlags } flags
192
192
* @param {V } value
193
193
* @param {import('./types.js').Block | null } block
194
- * @returns {import('./types.js').ComputationSignal<V> }
194
+ * @returns {import('./types.js').ComputationSignal<V> | import('./types.js').ComputationSignal<V> & import('./types.js').SourceSignalDebug }
195
195
*/
196
196
function create_computation_signal ( flags , value , block ) {
197
+ if ( DEV ) {
198
+ return {
199
+ // block
200
+ b : block ,
201
+ // consumers
202
+ c : null ,
203
+ // destroy
204
+ d : null ,
205
+ // equals
206
+ e : null ,
207
+ // flags
208
+ f : flags ,
209
+ // init
210
+ i : null ,
211
+ // references
212
+ r : null ,
213
+ // value
214
+ v : value ,
215
+ // context: We can remove this if we get rid of beforeUpdate/afterUpdate
216
+ x : null ,
217
+ // destroy
218
+ y : null ,
219
+ // this is for DEV only
220
+ inspect : new Set ( )
221
+ } ;
222
+ }
223
+
197
224
return {
198
225
// block
199
226
b : block ,
@@ -671,6 +698,12 @@ function update_derived(signal, force_schedule) {
671
698
if ( ! equals ( value , signal . v ) ) {
672
699
signal . v = value ;
673
700
mark_signal_consumers ( signal , DIRTY , force_schedule ) ;
701
+
702
+ // @ts -expect-error
703
+ if ( DEV && signal . inspect && force_schedule ) {
704
+ // @ts -expect-error
705
+ for ( const fn of signal . inspect ) fn ( ) ;
706
+ }
674
707
}
675
708
}
676
709
@@ -836,7 +869,15 @@ export function get(signal) {
836
869
}
837
870
838
871
if ( ( flags & DERIVED ) !== 0 && is_signal_dirty ( signal ) ) {
839
- update_derived ( /** @type {import('./types.js').ComputationSignal<V> } **/ ( signal ) , false ) ;
872
+ if ( DEV ) {
873
+ // we want to avoid tracking indirect dependencies
874
+ const previous_inspect_fn = inspect_fn ;
875
+ inspect_fn = null ;
876
+ update_derived ( /** @type {import('./types.js').ComputationSignal<V> } **/ ( signal ) , false ) ;
877
+ inspect_fn = previous_inspect_fn ;
878
+ } else {
879
+ update_derived ( /** @type {import('./types.js').ComputationSignal<V> } **/ ( signal ) , false ) ;
880
+ }
840
881
}
841
882
return signal . v ;
842
883
}
0 commit comments