Created
November 10, 2014 08:26
-
-
Save sergi/e68f6b3cca60bcf39fd9 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
var DBNAME = 'tabgrenade'; | |
var DBVERSION = 1; | |
var STORENAME = 'keyvaluepairs'; | |
var db = null; | |
function withStore(type, f) { | |
if (db) { | |
f(db.transaction(STORENAME, type).objectStore(STORENAME)); | |
} else { | |
var openreq = indexedDB.open(DBNAME, DBVERSION); | |
openreq.onerror = function withStoreOnError() { | |
console.error("asyncStorage: can't open database:", openreq.error.name); | |
}; | |
openreq.onupgradeneeded = function withStoreOnUpgradeNeeded() { | |
// First time setup: create an empty object store | |
openreq.result.createObjectStore(STORENAME); | |
}; | |
openreq.onsuccess = function withStoreOnSuccess() { | |
db = openreq.result; | |
f(db.transaction(STORENAME, type).objectStore(STORENAME)); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment