1
0
Fork 0
mirror of synced 2024-09-18 10:20:11 +12:00

Only clear change cache for keys which have been saved and haven't been further altered since the request started!

This commit is contained in:
Andrew Kingston 2024-05-29 09:51:01 +01:00
parent 35842525c5
commit e1ee233aaf

View file

@ -404,8 +404,11 @@ export const createActions = context => {
// Save change // Save change
try { try {
// Mark as in progress // Incremenet change count for this row
inProgressChanges.update(state => ({ ...state, [rowId]: true })) inProgressChanges.update(state => ({
...state,
[rowId]: (state[rowId] || 0) + 1,
}))
// Update row // Update row
const changes = get(rowChangeCache)[rowId] const changes = get(rowChangeCache)[rowId]
@ -423,17 +426,25 @@ export const createActions = context => {
await refreshRow(saved.id) await refreshRow(saved.id)
} }
// Wipe row change cache now that we've saved the row // Wipe row change cache for any values which have been saved
const liveChanges = get(rowChangeCache)[rowId]
rowChangeCache.update(state => { rowChangeCache.update(state => {
delete state[rowId] Object.keys(changes || {}).forEach(key => {
if (changes[key] === liveChanges?.[key]) {
delete state[rowId][key]
}
})
return state return state
}) })
} catch (error) { } catch (error) {
handleValidationError(rowId, error) handleValidationError(rowId, error)
} }
// Mark as completed // Decrement change count for this row
inProgressChanges.update(state => ({ ...state, [rowId]: false })) inProgressChanges.update(state => ({
...state,
[rowId]: (state[rowId] || 1) - 1,
}))
} }
// Updates a value of a row // Updates a value of a row