-
Notifications
You must be signed in to change notification settings - Fork 72
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
How to add a custom localforage to forerunnerdb? #225
Comments
Hi there. According to the documentation on that page, you just need to load the sql lite driver after loading localforage. Since localforage gets wrapped in ForerunnerDB's code you can load the driver after loading ForerunnerDB's js file. The main complexity is that we don't expose libraries to the window by default because that could create global naming conflicts. Therefore in order to access localforage from ForerunnerDB you need to know where it is located, which is here:
From their documentation you just need to do something like this (notice I have replaced loading localforage.js with ForerunnerDB instead): <script src="cordova.js"></script>
<script src="lib/ForerunnerDB/dist/fdb-all.min.js"></script>
<script src="lib/localForage-cordovaSQLiteDriver/dist/localforage-cordovasqlitedriver.js"></script>
<script>
// Expose localforage to the global scope - I wouldn't do it this way but it's up to you :)
window.localforage = ForerunnerDB.shared.modules.Persist.prototype.localforage;
localforage.defineDriver(window.cordovaSQLiteDriver).then(function() {
return localforage.setDriver([
// Try setting cordovaSQLiteDriver if available,
window.cordovaSQLiteDriver._driver,
// otherwise use one of the default localforage drivers as a fallback.
// This should allow you to transparently do your tests in a browser
localforage.INDEXEDDB,
localforage.WEBSQL,
localforage.LOCALSTORAGE
]);
}).then(function() {
// this should alert "cordovaSQLiteDriver" when in an emulator or a device
alert(localforage.driver());
// set a value;
return localforage.setItem('testPromiseKey', 'testPromiseValue');
}).then(function() {
return localforage.getItem('testPromiseKey');
}).then(function(value) {
alert(value);
}).catch(function(err) {
alert(err);
});
</script> I haven't tested this code but it should work just fine! |
this is what is was missing
maybe should doc this 👍 thanks |
Awesome. I'll add it to the docs! |
I'm will try to use this plugin to persist on IOS and break the size limitations of browser storage.
https://github.com/thgreasi/localForage-cordovaSQLiteDriver
Yet, don't know how to add this to forerunnerdb.
The text was updated successfully, but these errors were encountered: