@@ -37,6 +37,8 @@ let current_scheduler_mode = FLUSH_MICROTASK;
3737// Used for handling scheduling
3838let is_micro_task_queued = false ;
3939let is_task_queued = false ;
40+ // Used for $inspect
41+ export let is_batching_effect = false ;
4042
4143// Handle effect queues
4244
@@ -62,8 +64,8 @@ let current_dependencies = null;
6264let current_dependencies_index = 0 ;
6365/** @type {null | import('./types.js').Signal[] } */
6466let current_untracked_writes = null ;
65- // Handling capturing of signals from object property getters
66- let current_should_capture_signal = false ;
67+ /** @type { null | import('./types.js').Signal } */
68+ let last_inspected_signal = null ;
6769/** If `true`, `get`ting the signal should not register it as a dependency */
6870export let current_untracking = false ;
6971/** Exists to opt out of the mutation validation for stores which may be set for the first time during a derivation */
@@ -110,6 +112,29 @@ function is_runes(context) {
110112 return component_context !== null && component_context . r ;
111113}
112114
115+ /**
116+ * @param {import("./proxy/proxy.js").StateObject } target
117+ * @param {string | symbol } prop
118+ * @param {any } receiver
119+ */
120+ export function batch_inspect ( target , prop , receiver ) {
121+ const value = Reflect . get ( target , prop , receiver ) ;
122+ return function ( ) {
123+ const previously_batching_effect = is_batching_effect ;
124+ is_batching_effect = true ;
125+ try {
126+ return Reflect . apply ( value , receiver , arguments ) ;
127+ } finally {
128+ is_batching_effect = previously_batching_effect ;
129+ if ( last_inspected_signal !== null ) {
130+ // @ts -expect-error
131+ for ( const fn of last_inspected_signal . inspect ) fn ( ) ;
132+ last_inspected_signal = null ;
133+ }
134+ }
135+ } ;
136+ }
137+
113138/**
114139 * @param {null | import('./types.js').ComponentContext } context_stack_item
115140 * @returns {void }
@@ -1053,8 +1078,12 @@ export function set_signal_value(signal, value) {
10531078
10541079 // @ts -expect-error
10551080 if ( DEV && signal . inspect ) {
1056- // @ts -expect-error
1057- for ( const fn of signal . inspect ) fn ( ) ;
1081+ if ( is_batching_effect ) {
1082+ last_inspected_signal = signal ;
1083+ } else {
1084+ // @ts -expect-error
1085+ for ( const fn of signal . inspect ) fn ( ) ;
1086+ }
10581087 }
10591088 }
10601089}
0 commit comments