Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to listen to the close event? #1211

Closed
jsrilapan opened this issue Jan 20, 2021 · 3 comments
Closed

Is there a way to listen to the close event? #1211

jsrilapan opened this issue Jan 20, 2021 · 3 comments

Comments

@jsrilapan
Copy link
Contributor

Hello there, I'm looking for a way to catch a close event when the user explicitly deletes the database.
For example, user clears browsing data or just deletes database from the Chrome dev tools.

The native IDBDatabase interface has this onclose event handler. It will fired when the situations above occurred so I was wondering if there is a possible way that Dexie can listen or expose that event too?

Thanks in advance.

@dfahlander
Copy link
Collaborator

dfahlander commented Jan 20, 2021

Dexie should definitely have its own on('close') API (PR welcome!) but for now you can do the following:

const db = new Dexie("dbname");
db.on('ready', () => {
  db.backendDB().onclose = event => {
    myAppShowAlert('The database "' + db.name + '" has unexpectedly closed.');
  };
});

https://dexie.org/docs/Dexie/Dexie.on.ready

https://dexie.org/docs/Dexie/Dexie.backendDB()

@jsrilapan
Copy link
Contributor Author

Thanks for your respond, I will make a PR when it's ready.

@dfahlander
Copy link
Collaborator

Solved in #1212

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants