ionic-team / ionic-team/ionic-storage

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

Open
#228 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
456
Forks
97
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/ionic-team/ionic-storage/blob/b67aa24a89a7cf02aa391becebd620f87518c8af/lib/src/index.ts#L3))?

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](https://github.com/ionic-team/ionic-storage/blob/main/lib/src/index.ts#L45). It's also used in the [example code in the docs](https://github.com/ionic-team/ionic-storage#with-angular).

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)`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.