(
source: Accessor<unknown> | Solid.Signal,
options: DebugSignalOptions = {},
)
| 278 | * ``` |
| 279 | */ |
| 280 | export 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 | } |
no test coverage detected
searching dependent graphs…