Created
March 13, 2019 16:08
-
-
Save quasicomputational/21b22237c581649d76bb5e5c9171d481 to your computer and use it in GitHub Desktop.
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
import indexedDB from "fake-indexeddb"; | |
import IDBKeyRange from 'fake-indexeddb/lib/FDBKeyRange'; | |
import IDBIndex from 'fake-indexeddb/lib/FDBIndex'; | |
import IDBCursor from 'fake-indexeddb/lib/FDBCursor'; | |
import IDBDatabase from 'fake-indexeddb/lib/FDBDatabase'; | |
import IDBTransaction from 'fake-indexeddb/lib/FDBTransaction'; | |
import IDBObjectStore from 'fake-indexeddb/lib/FDBObjectStore'; | |
import IDBRequest from 'fake-indexeddb/lib/FDBRequest'; | |
global.indexedDB = indexedDB; | |
global.IDBKeyRange = IDBKeyRange; | |
global.IDBIndex = IDBIndex; | |
global.IDBTransaction = IDBTransaction; | |
global.IDBDatabase = IDBDatabase; | |
global.IDBCursor = IDBCursor; | |
global.IDBObjectStore = IDBObjectStore; | |
global.IDBRequest = IDBRequest; | |
export const STORE = "store"; | |
import { wrap, unwrap } from "idb"; | |
export const checkForGarbage = async () => { | |
const dbReq = indexedDB.open("db", 1); | |
dbReq.addEventListener("upgradeneeded", (ev) => { | |
ev.target.result.createObjectStore(STORE, { autoIncrement: true }); | |
}); | |
dbReq.addEventListener("success", (ev) => { | |
const db = wrap(ev.target.result); | |
// Comment this line and uncomment the following one to see five 'Done!' lines instead of two. | |
const tx = unwrap(db.transaction([STORE], "readwrite")); | |
//const tx = unwrap(db).transaction([STORE], "readwrite"); | |
const store = tx.objectStore(STORE); | |
store.get(0).addEventListener("success", () => console.log("Done!")); | |
}); | |
}; | |
for (let i = 0; i < 5; i++) { | |
checkForGarbage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment