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

Is it possible to use persistent with IndexedDB? #19

Closed
felixakiragreen opened this issue Feb 22, 2022 · 2 comments
Closed

Is it possible to use persistent with IndexedDB? #19

felixakiragreen opened this issue Feb 22, 2022 · 2 comments

Comments

@felixakiragreen
Copy link

Through reading the documentation I saw a section on Persistent Engines and switching localStorage out for other engines.

However, I am not sure of how to approach this.

  1. Do you recommend using another 3rd party library (like idb, dexie) or should I try to use the indexedDB API directly?
  2. If I wanted to use IndexedDB instead of localStorage, would it be better to use it directly without going through nanostores/persistent?
  3. If I were to move ahead with using IndexedDB as the persistent engine, how should I approach the async nature of it?
@ai
Copy link
Member

ai commented Feb 22, 2022

Do you recommend using another 3rd party library (like idb, dexie) or should I try to use the indexedDB API directly?

I prefer to use direct API. Many npm tools are suffer from bad design which lead to JS bundle size bloat.

If I wanted to use IndexedDB instead of localStorage, would it be better to use it directly without going through nanostores/persistent?

I think that localStorage and IndexedDB should be used for different purposes. Don’t change the engine because of the trends. Settings are still better to put to localStorage.

IndexedDB is good for long lists (like 1-10 MB of data). nanostores/persistent API was created to work with small settings, not with long lists of data. It will be better to add another stores with different API.

For instance, there is SyncMap stores in @logux/client which uses Nano Stores and IndexedDB (to put events list there, so it is a little more complicated that you may look for).

If I were to move ahead with using IndexedDB as the persistent engine, how should I approach the async nature of it?

You will need some key to mark that store is loading. For instance, SyncMap has if (value.isLoading) { renderLoader() } else { renderUI() }.

I am closing this issue since it is more like a question.

@ai ai closed this as completed Feb 22, 2022
@felixakiragreen
Copy link
Author

🙏 Thank you very much for this detailed reply!

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

2 participants