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

Function configMutationFn

examples/react/todo/src/routes/electric.tsx:38–69  ·  view source on GitHub ↗
({
    transaction,
  }: {
    transaction: Transaction
  })

Source from the content-addressed store, hash-verified

36
37 // Electric collections use txid to track sync
38 const configMutationFn = async ({
39 transaction,
40 }: {
41 transaction: Transaction
42 }) => {
43 const txids: Array<number> = []
44
45 // Handle inserts
46 const inserts = transaction.mutations.filter((m) => m.type === `insert`)
47 for (const mutation of inserts) {
48 const response = await api.config.create(mutation.modified)
49 txids.push(response.txid)
50 }
51
52 // Handle updates
53 const updates = transaction.mutations.filter((m) => m.type === `update`)
54 for (const mutation of updates) {
55 if (!(`id` in mutation.original)) {
56 throw new Error(`Original config not found for update`)
57 }
58 const response = await api.config.update(
59 mutation.original.id,
60 mutation.changes,
61 )
62 txids.push(response.txid)
63 }
64
65 // Wait for all txids to sync back to the collection
66 await Promise.all(
67 txids.map((txid) => electricConfigCollection.utils.awaitTxid(txid)),
68 )
69 }
70
71 return (
72 <TodoApp

Callers

nothing calls this directly

Calls 3

filterMethod · 0.80
updateMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected