Skip to content
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

Open
regisdetoni opened this issue May 26, 2017 · 3 comments
Open

How to add a custom localforage to forerunnerdb? #225

regisdetoni opened this issue May 26, 2017 · 3 comments

Comments

@regisdetoni
Copy link

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.

@Irrelon
Copy link
Owner

Irrelon commented Jun 19, 2017

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:

ForerunnerDB.shared.modules.Persist.prototype.localforage

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!

@regisdetoni
Copy link
Author

regisdetoni commented Jun 19, 2017

this is what is was missing

ForerunnerDB.shared.modules.Persist.prototype.localforage

maybe should doc this 👍

thanks

@Irrelon
Copy link
Owner

Irrelon commented Jun 19, 2017

Awesome. I'll add it to the docs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants