updated with proper error handling for moves

This commit is contained in:
Matthew Rathbone
2026-03-04 16:32:15 -06:00
parent b7c68ac24c
commit 15001db415
2 changed files with 34 additions and 10 deletions

View File

@@ -72,14 +72,26 @@ export const UtilConnectionModule: DataStore<IConnection, State> = {
position: idx + 1
}))
// Snapshot affected items before mutation (upsert mutates in-place via Object.assign)
const affectedIds = new Set(updates.map(c => c.id))
const snapshot = context.state.items
.filter(c => affectedIds.has(c.id))
.map(c => ({ ...c }))
// Optimistic update
context.commit('upsert', updates)
// Save all items
const saved = await Promise.all(
updates.map(c => Vue.prototype.$util.send('appdb/saved/save', { obj: c }))
)
context.commit('upsert', saved)
try {
// Save all items
const saved = await Promise.all(
updates.map(c => Vue.prototype.$util.send('appdb/saved/save', { obj: c }))
)
context.commit('upsert', saved)
} catch (e) {
// Revert optimistic update using pre-mutation snapshots
context.commit('upsert', snapshot)
throw e
}
return item.id
}

View File

@@ -71,14 +71,26 @@ export const UtilQueryModule: DataStore<TransportFavoriteQuery, DataState<Transp
position: idx + 1
}))
// Snapshot affected items before mutation (upsert mutates in-place via Object.assign)
const affectedIds = new Set(updates.map(q => q.id))
const snapshot = context.state.items
.filter(q => affectedIds.has(q.id))
.map(q => ({ ...q }))
// Optimistic update
context.commit('upsert', updates)
// Save all items
const saved = await Promise.all(
updates.map(q => Vue.prototype.$util.send('appdb/query/save', { obj: q }))
)
context.commit('upsert', saved)
try {
// Save all items
const saved = await Promise.all(
updates.map(q => Vue.prototype.$util.send('appdb/query/save', { obj: q }))
)
context.commit('upsert', saved)
} catch (e) {
// Revert optimistic update using pre-mutation snapshots
context.commit('upsert', snapshot)
throw e
}
return item.id
}