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

Function updateCollapsedValue

packages/frontend/src/decode.ts:239–273  ·  view source on GitHub ↗
(
    data: DecodedValue<ValueType.Object | ValueType.Array | ValueType.Store>,
    list: EncodedValue[],
    storeRefMap: StoreNodeMap,
)

Source from the content-addressed store, hash-verified

237 * The previous value is important for removing store references that are no longer in the tree.
238 */
239export function updateCollapsedValue(
240 data: DecodedValue<ValueType.Object | ValueType.Array | ValueType.Store>,
241 list: EncodedValue[],
242 storeRefMap: StoreNodeMap,
243): void {
244 if (data.type !== list[0]![0]) throw new Error('Type mismatch')
245
246 List = list
247 StoreRefMap = storeRefMap
248 Seen = new Set()
249 DecodedMap = new Map()
250
251 // the relevant value for the store is the second item in the list
252 const head = (
253 list[data.type === ValueType.Store ? 1 : 0] as EncodedValue<
254 ValueType.Object | ValueType.Array
255 >
256 )[1]
257
258 // collapse object value
259 if (data.value && typeof head === 'number') {
260 Object.values(data.value).forEach(removeNestedStoreRefs)
261 data.setValue(head)
262 }
263 // expand object value
264 else if (!data.value && typeof head !== 'number') {
265 const newValue: Record<string | number, DecodedValue> = head.constructor()
266 for (const [key, index] of Object.entries(head)) {
267 newValue[key] = index === -1 ? {type: ValueType.Getter, name: key} : decode(index)
268 }
269 data.setValue(newValue)
270 }
271
272 StoreRefMap = List = Seen = DecodedMap = undefined!
273}

Callers

nothing calls this directly

Calls 2

decodeFunction · 0.85
constructorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…