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

Function decode

packages/frontend/src/decode.ts:79–180  ·  view source on GitHub ↗
(index: number)

Source from the content-addressed store, hash-verified

77}
78
79function decode(index: number): DecodedValue {
80 if (DecodedMap.has(index)) {
81 return DecodedMap.get(index)!
82 }
83
84 const encoded = List[index]!
85 switch (encoded[0]) {
86 case ValueType.String:
87 case ValueType.Boolean:
88 return {type: encoded[0], value: encoded[1] as any}
89 case ValueType.Null:
90 return {type: ValueType.Null, value: encoded[1] === UNDEFINED ? undefined : null}
91 case ValueType.Number: {
92 const [, data] = encoded
93 const value =
94 data === INFINITY
95 ? Infinity
96 : data === NEGATIVE_INFINITY
97 ? -Infinity
98 : data === NAN
99 ? NaN
100 : data
101 return {type: ValueType.Number, value}
102 }
103 case ValueType.Symbol:
104 return {type: ValueType.Symbol, name: encoded[1]}
105 case ValueType.Instance:
106 case ValueType.Function:
107 case ValueType.Getter:
108 return saveToMap(index, {type: encoded[0], name: encoded[1]})
109 case ValueType.Element: {
110 const [id, name] = splitOnColon(encoded[1])
111 return saveToMap(index, {type: ValueType.Element, id, name})
112 }
113 case ValueType.Array:
114 case ValueType.Object: {
115 const [type, data] = encoded
116
117 const [length, setLength] = createSignal(
118 typeof data === 'number'
119 ? data
120 : Array.isArray(data)
121 ? data.length
122 : Object.keys(data).length,
123 )
124 const initValue =
125 typeof data === 'number' ? null : (data.constructor() as ObjectValueData['value'])
126 const [value, setActualValue] = createSignal<ObjectValueData['value']>(initValue)
127
128 const valueObject: ObjectValueData = saveToMap(index, {
129 type,
130 get value() {return value()},
131 get length() {return length()},
132 setValue(newValue) {
133 batch(() => {
134 if (typeof newValue === 'number') {
135 setLength(newValue)
136 setActualValue(null)

Callers 2

decodeValueFunction · 0.85
updateCollapsedValueFunction · 0.85

Calls 5

splitOnColonFunction · 0.90
saveToMapFunction · 0.85
getMethod · 0.80
addRefMethod · 0.80
constructorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…