Skip to content

Instantly share code, notes, and snippets.

@mikeknoop
Last active December 30, 2015 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeknoop/7749020 to your computer and use it in GitHub Desktop.
Save mikeknoop/7749020 to your computer and use it in GitHub Desktop.
# APPLICATION CODE (uses underscore.js)
lawnchair = new Lawnchair({}, (->))
# hackery to cope with firefox and lawnchair, indexedDB not doing asnyc validation
# so well. If indexedDB isn't available (after doing a .open() check) then remove it
# from the available adapters and re-init lawnchair with a new instance.
# see: https://github.com/brianleroux/lawnchair/issues/189
indexedDBValid = (callback) =>
idb = window.indexedDB or window.webkitIndexedDB or window.mozIndexedDB or window.oIndexedDB or window.msIndexedDB
# open a db to see if it's accessible. firefox won't let you open a db under certain scenarios
# like if your privacy history setting is "never remember history"
request = idb.open('test', 3)
request.onsucess = => callback(true)
request.onerror = => callback(false)
indexedDBValid (valid) =>
if not valid
# build a list of adapters with indexed-db removed
adapters = _.filter Lawnchair.adapters, ((adpt) => adpt.adapter != 'indexed-db')
adapters = _.map adapters, ((adpt) => return adpt.adapter)
# re-init with our specific list of adapters
lawnchair = new Lawnchair({adapter: adapters}, (->))
# MODIFICATIONS TO INDEXDB.JS
# Replace "request.onerror" methond on line 121 with
request.onerror = function(ev) {
if (request.errorCode === getIDBDatabaseException().VERSION_ERR) {
// xxx blow it away
self.idb.deleteDatabase(self.name);
// try it again (but only once more so we dont infinite loop)
if (!options.recursing) {
options.recursing = true
return self.init(options, callback);
}
}
console.error('Failed to open database');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment