MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / debugSignal

Function debugSignal

packages/logger/src/index.ts:280–351  ·  view source on GitHub ↗
(
    source: Accessor<unknown> | Solid.Signal,
    options: DebugSignalOptions = {},
)

Source from the content-addressed store, hash-verified

278 * ```
279 */
280export function debugSignal(
281 source: Accessor<unknown> | Solid.Signal,
282 options: DebugSignalOptions = {},
283): void {
284 let signal: Solid.Signal
285
286 if (typeof source === 'function') {
287 const sources = getFunctionSources(source)
288 if (sources.length === 0) return console.warn('No signal was passed to debugSignal')
289 else if (sources.length > 1)
290 return console.warn('More then one signal was passed to debugSignal')
291 signal = sources[0]!
292 } else {
293 signal = source
294 }
295
296 if (markDebugNode(signal) === true) return
297
298 const {trackObservers = true, logInitialValue: _logInitialValue = true} = options
299
300 const state = getNodeState(signal)
301 const SYMBOL = Symbol(state.name)
302
303 // Initial
304 _logInitialValue && logInitialValue({...state, value: signal.value})
305
306 let actualObservers: Solid.Computation[]
307 let prevObservers: Solid.Computation[] = []
308 let actualPrevObservers: Solid.Computation[] = []
309
310 if (!signal.observers) {
311 signal.observers = []
312 signal.observerSlots = []
313 }
314
315 // Value Update
316 makeValueUpdateListener(
317 signal,
318 (value, prev) => {
319 logSignalValueUpdate(
320 state,
321 value,
322 prev,
323 trackObservers ? prevObservers : array.deduped(signal.observers!),
324 )
325 },
326 SYMBOL,
327 )
328
329 if (trackObservers) {
330 // Observers Change
331 function logObserversChange(): void {
332 const observers = array.deduped(actualObservers)
333 if (array.includes_same_members(observers, prevObservers)) return
334 logObservers(state.name, observers, prevObservers)
335 prevObservers = [...observers]
336 actualPrevObservers = [...actualObservers]
337 }

Callers 1

debugSignalsFunction · 0.85

Calls 9

getFunctionSourcesFunction · 0.90
getNodeStateFunction · 0.90
logInitialValueFunction · 0.90
makeValueUpdateListenerFunction · 0.90
logSignalValueUpdateFunction · 0.90
addSolidUpdateListenerFunction · 0.90
markDebugNodeFunction · 0.85
onCleanupFunction · 0.85
logObserversChangeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…