@@ -37,6 +37,8 @@ let current_scheduler_mode = FLUSH_MICROTASK;
37
37
// Used for handling scheduling
38
38
let is_micro_task_queued = false ;
39
39
let is_task_queued = false ;
40
+ // Used for $inspect
41
+ export let is_batching_effect = false ;
40
42
41
43
// Handle effect queues
42
44
@@ -62,8 +64,8 @@ let current_dependencies = null;
62
64
let current_dependencies_index = 0 ;
63
65
/** @type {null | import('./types.js').Signal[] } */
64
66
let 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 ;
67
69
/** If `true`, `get`ting the signal should not register it as a dependency */
68
70
export let current_untracking = false ;
69
71
/** 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) {
110
112
return component_context !== null && component_context . r ;
111
113
}
112
114
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
+
113
138
/**
114
139
* @param {null | import('./types.js').ComponentContext } context_stack_item
115
140
* @returns {void }
@@ -1053,8 +1078,12 @@ export function set_signal_value(signal, value) {
1053
1078
1054
1079
// @ts -expect-error
1055
1080
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
+ }
1058
1087
}
1059
1088
}
1060
1089
}
0 commit comments