Skip to content

Commit

Permalink
Fixes after unit test failures:
Browse files Browse the repository at this point in the history
* New options to db.close({disableAutoOpen}) default: {disableAutoOpen: true} (backward compatible).
* Made db.delete() call close() with options instead of calling db._close()
* resolveDbReady no in dexie-open no matter parallell open calls.
  • Loading branch information
dfahlander committed Jul 4, 2023
1 parent 22a7b66 commit 10938c2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/classes/dexie/dexie-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,8 @@ export function dexieOpen (db: Dexie) {
}
return rejection (err);
}).finally(()=>{
if (state.openCanceller === openCanceller) {
// Our openCanceller is the same as the one that was set when calling db.open().
// This means that we weren't cancelled.
state.openComplete = true;
resolveDbReady(); // dbReadyPromise is resolved no matter if open() rejects or resolved. It's just to wake up waiters.
}
state.openComplete = true;
resolveDbReady(); // dbReadyPromise is resolved no matter if open() rejects or resolved. It's just to wake up waiters.
}).then(()=>{
if (wasCreated) {
// Propagate full range on primary keys and indexes on all tables now that the DB is ready and opened,
Expand Down
9 changes: 4 additions & 5 deletions src/classes/dexie/dexie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class Dexie implements IDexie {
console.warn(`Another connection wants to upgrade database '${this.name}'. Closing db now to resume the upgrade.`);
else
console.warn(`Another connection wants to delete database '${this.name}'. Closing db now to resume the delete request.`);
this._close();
this.close({disableAutoOpen: false});
this._state.openComplete = false;
// In many web applications, it would be recommended to force window.reload()
// when this event occurs. To do that, subscribe to the versionchange event
Expand Down Expand Up @@ -307,13 +307,12 @@ export class Dexie implements IDexie {
state.openCanceller = new Promise((_, reject) => {
state.cancelOpen = reject;
});
state.dbOpenError = null;
}

close(): void {
close({disableAutoOpen} = {disableAutoOpen: true}): void {
this._close();
const state = this._state;
this._options.autoOpen = false;
if (disableAutoOpen) this._options.autoOpen = false;
state.dbOpenError = new exceptions.DatabaseClosed();
if (state.isBeingOpened)
state.cancelOpen(state.dbOpenError);
Expand All @@ -324,7 +323,7 @@ export class Dexie implements IDexie {
const state = this._state;
return new Promise((resolve, reject) => {
const doDelete = () => {
this._close();
this.close({disableAutoOpen: false});
var req = this._deps.indexedDB.deleteDatabase(this.name);
req.onsuccess = wrap(() => {
_onDatabaseDeleted(this._deps, this.name);
Expand Down
2 changes: 1 addition & 1 deletion src/public/types/dexie.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface Dexie {
scope: (trans: TXWithTables<this>) => PromiseLike<U> | U
): PromiseExtended<U>;

close(): void;
close(closeOptions?: {disableAutoOpen: boolean}): void;

delete(): PromiseExtended<void>;

Expand Down

0 comments on commit 10938c2

Please sign in to comment.