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

Function syncItems

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

Source from the content-addressed store, hash-verified

231}
232
233async function syncItems({
234 transaction,
235}: {
236 transaction: { mutations: Array<PendingMutation> }
237 idempotencyKey: string
238}) {
239 for (const mutation of transaction.mutations) {
240 const data = mutation.modified as ShoppingItem
241 switch (mutation.type) {
242 case `insert`: {
243 const created = await itemsApi.create({
244 id: data.id,
245 listId: data.listId,
246 text: data.text,
247 checked: data.checked,
248 createdAt: data.createdAt,
249 })
250 await itemsCollection.utils.awaitTxId(created.txid)
251 break
252 }
253 case `update`: {
254 const updated = await itemsApi.update(data.id, {
255 text: data.text,
256 checked: data.checked,
257 })
258 if (updated) {
259 await itemsCollection.utils.awaitTxId(updated.txid)
260 }
261 break
262 }
263 case `delete`: {
264 const deleted = await itemsApi.delete(
265 (mutation.original as ShoppingItem).id,
266 )
267 if (deleted) {
268 await itemsCollection.utils.awaitTxId(deleted.txid)
269 }
270 break
271 }
272 }
273 }
274}
275
276export function createOfflineExecutor() {
277 return startOfflineExecutor({

Callers

nothing calls this directly

Calls 2

updateMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected