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

Function classifyDelta

packages/db/src/query/effect.ts:1056–1085  ·  view source on GitHub ↗

Classify accumulated per-key changes into a DeltaEvent

(
  key: TKey,
  changes: EffectChanges<TRow>,
)

Source from the content-addressed store, hash-verified

1054
1055/** Classify accumulated per-key changes into a DeltaEvent */
1056function classifyDelta<TRow extends object, TKey extends string | number>(
1057 key: TKey,
1058 changes: EffectChanges<TRow>,
1059): DeltaEvent<TRow, TKey> | undefined {
1060 const { inserts, deletes, insertValue, deleteValue } = changes
1061
1062 if (inserts > 0 && deletes === 0) {
1063 // Row entered the query result
1064 return { type: `enter`, key, value: insertValue! }
1065 }
1066
1067 if (deletes > 0 && inserts === 0) {
1068 // Row exited the query result — value is the exiting value,
1069 // previousValue is omitted (it would be identical to value)
1070 return { type: `exit`, key, value: deleteValue! }
1071 }
1072
1073 if (inserts > 0 && deletes > 0) {
1074 // Row updated within the query result
1075 return {
1076 type: `update`,
1077 key,
1078 value: insertValue!,
1079 previousValue: deleteValue!,
1080 }
1081 }
1082
1083 // inserts === 0 && deletes === 0 — no net change (should not happen)
1084 return undefined
1085}
1086
1087/** Track a promise in the in-flight set, automatically removing on settlement */
1088function trackPromise(

Callers 1

flushPendingChangesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected