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

Function syncLists

examples/react-native/shopping-list/src/db/collections.ts:195–231  ·  view source on GitHub ↗
({
  transaction,
}: {
  transaction: { mutations: Array<PendingMutation> }
  idempotencyKey: string
})

Source from the content-addressed store, hash-verified

193)
194
195async function syncLists({
196 transaction,
197}: {
198 transaction: { mutations: Array<PendingMutation> }
199 idempotencyKey: string
200}) {
201 for (const mutation of transaction.mutations) {
202 const data = mutation.modified as ShoppingList
203 switch (mutation.type) {
204 case `insert`: {
205 const created = await listsApi.create({
206 id: data.id,
207 name: data.name,
208 createdAt: data.createdAt,
209 })
210 await listsCollection.utils.awaitTxId(created.txid)
211 break
212 }
213 case `update`: {
214 const updated = await listsApi.update(data.id, { name: data.name })
215 if (updated) {
216 await listsCollection.utils.awaitTxId(updated.txid)
217 }
218 break
219 }
220 case `delete`: {
221 const deleted = await listsApi.delete(
222 (mutation.original as ShoppingList).id,
223 )
224 if (deleted) {
225 await listsCollection.utils.awaitTxId(deleted.txid)
226 }
227 break
228 }
229 }
230 }
231}
232
233async function syncItems({
234 transaction,

Callers

nothing calls this directly

Calls 2

updateMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected