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

Function debugProps

packages/logger/src/index.ts:468–539  ·  view source on GitHub ↗
(props: Record<string, unknown>)

Source from the content-addressed store, hash-verified

466 * ```
467 */
468export function debugProps(props: Record<string, unknown>): void {
469 const owner = getOwner() as Solid.Owner | null
470 if (!owner) return console.warn('debugProps should be used synchronously inside a component')
471
472 // for solid-refresh HMR memos, return the owned component
473 const ownerState = getNodeState(lookupOwner(owner, o => getOwnerType(o) !== NodeType.Refresh)!)
474 const isProxy = isSolidProxy(props)
475
476 const descriptorsList = Object.entries(Object.getOwnPropertyDescriptors(props))
477
478 if (descriptorsList.length === 0) console.log(...getPropsInitLabel(ownerState, isProxy, true))
479 else {
480 console.groupCollapsed(...getPropsInitLabel(ownerState, isProxy, false))
481 paddedForEach(
482 descriptorsList,
483 ([, desc]) => (desc.get ? 'Getter' : 'Value'),
484 (type, [key, desc]) => {
485 const value = getPropValue(props, desc)
486 const signals = type === 'Getter' ? getFunctionSources(() => props[key]) : []
487 const label = getPropLabel(type, key, value, null)
488
489 if (signals.length > 0) {
490 console.groupCollapsed(...label)
491 signals.forEach(logSignalValue)
492 console.groupEnd()
493 } else console.log(...label)
494 },
495 )
496 console.groupEnd()
497 }
498
499 if (isProxy) {
500 createEffect(
501 on(
502 () => Object.keys(props),
503 (keys, prevKeys) => {
504 if (!prevKeys) return
505 if (arrayEquals(keys, prevKeys)) return
506
507 const descriptors = Object.getOwnPropertyDescriptors(props)
508
509 if (Object.entries(descriptors).length === 0) {
510 console.log(...getPropsKeyUpdateLabel(ownerState, true))
511 } else {
512 const [getMark, allKeys] = getDiffMap(prevKeys, keys, Map)
513 console.groupCollapsed(...getPropsKeyUpdateLabel(ownerState, false))
514 allKeys.forEach(key => {
515 const mark = getMark(key)
516
517 if (mark === 'removed')
518 return console.log(...getPropLabel('Getter', key, null, 'removed'))
519
520 const desc = descriptors[key]!
521 const value = getPropValue(props, desc)
522 const label = getPropLabel('Getter', key, value, mark)
523 const signals = getFunctionSources(() => props[key])
524
525 if (signals.length > 0) {

Callers

nothing calls this directly

Calls 11

getNodeStateFunction · 0.90
lookupOwnerFunction · 0.90
getOwnerTypeFunction · 0.90
getPropsInitLabelFunction · 0.90
paddedForEachFunction · 0.90
getFunctionSourcesFunction · 0.90
getPropLabelFunction · 0.90
getPropsKeyUpdateLabelFunction · 0.90
getDiffMapFunction · 0.90
isSolidProxyFunction · 0.85
getPropValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…