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

Function encode

packages/debugger/src/inspector/serialize.ts:45–128  ·  view source on GitHub ↗
(
    value: unknown,
    eli:   ElementInterface<TEl>,
)

Source from the content-addressed store, hash-verified

43}
44
45function encode<TEl extends object>(
46 value: unknown,
47 eli: ElementInterface<TEl>,
48): number {
49 const ignoreNextStore = IgnoreNextSeen
50 if (ignoreNextStore) IgnoreNextSeen = false
51 else {
52 const seen = Seen.get(value)
53 if (seen !== undefined) return seen
54 }
55
56 // Non-Objects
57 if (!value || typeof value !== 'object') {
58 const index = List.push(encodeNonObject(value)) - 1
59 Seen.set(value, index)
60 return index
61 }
62
63 const encoded: EncodedValue = [] as any
64 const index = List.push(encoded) - 1
65 ignoreNextStore || Seen.set(value, index)
66
67 // HTML Elements
68 if (eli.isElement(value)) {
69 ;(encoded as EncodedValue<ValueType.Element>)[0] = ValueType.Element
70 let id = getSdtId(value, ObjectType.Element)
71 let name = eli.getName(value)
72 ;(encoded as EncodedValue<ValueType.Element>)[1] = `${id}:${name}`
73 }
74 // Store Nodes
75 else if (!ignoreNextStore && utils.isStoreNode(value)) {
76 // might still pass in a proxy
77 const node = setup.store.unwrap(value)
78 // set unwrapped as seen as well
79 if (node !== value) Seen.set(node, index)
80 const id = getSdtId(node, ObjectType.StoreNode)
81 !InStore && HandleStore && HandleStore(node, id)
82 const wasInStore = InStore
83 InStore = IgnoreNextSeen = true
84 ;(encoded as EncodedValue<ValueType.Store>)[0] = ValueType.Store
85 ;(encoded as EncodedValue<ValueType.Store>)[1] = `${id}:${encode(node, eli)}`
86 InStore = wasInStore
87 }
88 // Arrays
89 else if (Array.isArray(value)) {
90 ;(encoded as EncodedValue<ValueType.Array>)[0] = ValueType.Array
91 if (Deep) {
92 let data: number[] = Array(value.length)
93 for (let i = 0; i < value.length; i++) {
94 data[i] = encode(value[i], eli)
95 }
96 ;(encoded as EncodedValue<ValueType.Array>)[1] = data
97 } else {
98 ;(encoded as EncodedValue<ValueType.Array>)[1] = value.length
99 }
100 }
101 // Objects
102 else {

Callers 1

encodeValueFunction · 0.85

Calls 3

getSdtIdFunction · 0.90
encodeNonObjectFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…