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

curious why Drivers is @hidden and can it be made iterable? #228

Open
rtpHarry opened this issue Apr 24, 2021 · 0 comments
Open

curious why Drivers is @hidden and can it be made iterable? #228

rtpHarry opened this issue Apr 24, 2021 · 0 comments

Comments

@rtpHarry
Copy link
Contributor

rtpHarry commented Apr 24, 2021

OK so I'm just returning to some Angular stuff after about a year off and seems like I've arrived just as there are breaking changes required on the storage.

I'm working through the documentation and trying to distill the best practices out of it.

I'm adding in the sqlite support.

Driver Order

Firstly I got stuck a bit reading through the source code to make sure what the correct order of the drivers should be.

I'm aiming to use the sqllite driver, but it seems like it then puts the responsibility of taking control of all the other drivers as well. I didn't know which was the best order to put them in.

Reading through the code I've settled on this:

import { IonicStorageModule } from '@ionic/storage-angular';
import { Drivers } from '@ionic/storage';
import * as CordovaSQLiteDriver from 'localforage-cordovasqlitedriver';

@NgModule({
  // snip
  imports: [
    // snip
    IonicStorageModule.forRoot({
      driverOrder: [CordovaSQLiteDriver._driver, Drivers.IndexedDB, Drivers.LocalStorage]
    })  ],

Drivers Hidden

Which brings me to the second thing - why is the Drivers exported but @hidden (see here)?

This makes it feel like I shouldn't be using it, but I would prefer not to use strings in my list like the comments seem to hint at. It's also used in the example code in the docs.

Also the second code example only adds in one of them, which was confusing:

driverOrder: [CordovaSQLiteDriver._driver, Drivers.IndexedDB]

Drivers Iterable?

Finally, would it be possible / practical to make Drivers iterable? Instead of taking responsibility for getting the order right this time, and having to maintain that in the future, I thought I was being clever to try this:

driverOrder: [CordovaSQLiteDriver._driver, ...Drivers]

But the compiler politely declined that idea with:

Type '{ SecureStorage: string; IndexedDB: string; LocalStorage: string; }' must have a '[Symbol.iterator]()' method that returns an iterator.ts(2488)

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

No branches or pull requests

1 participant