Skip to content

Commit

Permalink
dont access database before it is created
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Jan 22, 2020
1 parent f5ca860 commit 4a23198
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/y-indexeddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,19 @@ export class IndexeddbPersistence extends Observable {
*/
this._storeUpdate = update =>
this._mux(() => {
const [updatesStore] = idb.transact(/** @type {IDBDatabase} */ (this.db), [updatesStoreName])
idb.addAutoKey(updatesStore, update)
if (++this._dbsize >= PREFERRED_TRIM_SIZE) {
if (this._storeTimeoutId !== null) {
clearTimeout(this._storeTimeoutId)
if (this.db) {
const [updatesStore] = idb.transact(/** @type {IDBDatabase} */ (this.db), [updatesStoreName])
idb.addAutoKey(updatesStore, update)
if (++this._dbsize >= PREFERRED_TRIM_SIZE) {
// debounce store call
if (this._storeTimeoutId !== null) {
clearTimeout(this._storeTimeoutId)
}
this._storeTimeoutId = setTimeout(() => {
storeState(this)
this._storeTimeoutId = null
}, this._storeTimeout)
}
this._storeTimeoutId = setTimeout(() => {
storeState(this)
this._storeTimeoutId = null
}, this._storeTimeout)
}
})
doc.on('update', this._storeUpdate)
Expand Down

0 comments on commit 4a23198

Please sign in to comment.