Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cde7167
commit d989abc
Showing
3 changed files
with
102 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { IDBPDatabase } from 'idb' | ||
|
||
export function createDBAccess<DBSchema>(opener: () => Promise<IDBPDatabase<DBSchema>>) { | ||
let db: IDBPDatabase<DBSchema> | undefined = undefined | ||
return async () => { | ||
if (db) return db | ||
db = await opener() | ||
db.addEventListener('close', e => (db = undefined)) | ||
return db | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters