Skip to content

Commit

Permalink
More stable deletion on broken log
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed May 16, 2024
1 parent 27147a4 commit 649a83d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions indexed-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,15 @@ export class IndexedStore {
return
}

entry.reasons = entry.reasons.filter(i => i !== reason)
entry.meta.reasons = entry.reasons

let process
if (entry.reasons.length === 1) {
entry.meta.reasons = []
if (entry.reasons.length === 0) {
entry.meta.added = entry.added
callback(entry.action, entry.meta)
process = log.delete(entry.added)
} else {
entry.reasons.splice(entry.reasons.indexOf(reason), 1)
entry.meta.reasons = entry.reasons
process = log.put(entry)
}

Expand Down
2 changes: 1 addition & 1 deletion indexed-store/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ it('works with broken lastSynced', async () => {
it('updates reasons cache', async () => {
store = new IndexedStore()
await store.add({ type: 'A' }, { added: 1, id: '1', reasons: ['a'], time: 1 })
await store.changeMeta('1', { reasons: ['a', 'b', 'c'] })
await store.changeMeta('1', { reasons: ['a', 'b', 'b', 'c'] })
await store.removeReason('b', {}, () => {})
await check(store, [
[{ type: 'A' }, { added: 1, id: '1', reasons: ['a', 'c'], time: 1 }]
Expand Down

0 comments on commit 649a83d

Please sign in to comment.