(
data: DecodedValue<ValueType.Object | ValueType.Array | ValueType.Store>,
list: EncodedValue[],
storeRefMap: StoreNodeMap,
)
| 237 | * The previous value is important for removing store references that are no longer in the tree. |
| 238 | */ |
| 239 | export 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…