MCPcopy Create free account
hub / github.com/TanStack/db / accumulateChanges

Function accumulateChanges

packages/db/src/query/live/collection-config-builder.ts:2299–2328  ·  view source on GitHub ↗
(
  acc: Map<unknown, Changes<T>>,
  [[key, tupleData], multiplicity]: [
    [unknown, [any, string | undefined]],
    number,
  ],
)

Source from the content-addressed store, hash-verified

2297}
2298
2299function accumulateChanges<T>(
2300 acc: Map<unknown, Changes<T>>,
2301 [[key, tupleData], multiplicity]: [
2302 [unknown, [any, string | undefined]],
2303 number,
2304 ],
2305) {
2306 // All queries now consistently return [value, orderByIndex] format
2307 // where orderByIndex is undefined for queries without ORDER BY
2308 const [value, orderByIndex] = tupleData as [T, string | undefined]
2309
2310 const changes = acc.get(key) || {
2311 deletes: 0,
2312 inserts: 0,
2313 value,
2314 orderByIndex,
2315 }
2316 if (multiplicity < 0) {
2317 changes.deletes += Math.abs(multiplicity)
2318 } else if (multiplicity > 0) {
2319 changes.inserts += multiplicity
2320 // Update value to the latest version for this key
2321 changes.value = value
2322 if (orderByIndex !== undefined) {
2323 changes.orderByIndex = orderByIndex
2324 }
2325 }
2326 acc.set(key, changes)
2327 return acc
2328}

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected