Skip to content

Commit

Permalink
dont apply updates if y-indexeddb is already destroyed - replaces #27
Browse files Browse the repository at this point in the history
…- related to #25
  • Loading branch information
dmonad committed Mar 30, 2023
1 parent 217fd6d commit 9a9112b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/y-indexeddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ export const PREFERRED_TRIM_SIZE = 500
export const fetchUpdates = (idbPersistence, beforeApplyUpdatesCallback = () => {}) => {
const [updatesStore] = idb.transact(/** @type {IDBDatabase} */ (idbPersistence.db), [updatesStoreName]) // , 'readonly')
return idb.getAll(updatesStore, idb.createIDBKeyRangeLowerBound(idbPersistence._dbref, false)).then(updates => {
beforeApplyUpdatesCallback(updatesStore)
Y.transact(idbPersistence.doc, () => {
updates.forEach(val => Y.applyUpdate(idbPersistence.doc, val))
}, idbPersistence, false)
if (!idbPersistence._destroyed) {
beforeApplyUpdatesCallback(updatesStore)
Y.transact(idbPersistence.doc, () => {
updates.forEach(val => Y.applyUpdate(idbPersistence.doc, val))
}, idbPersistence, false)
}
})
.then(() => idb.getLastKey(updatesStore).then(lastKey => { idbPersistence._dbref = lastKey + 1 }))
.then(() => idb.count(updatesStore).then(cnt => { idbPersistence._dbsize = cnt }))
Expand Down

0 comments on commit 9a9112b

Please sign in to comment.