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

withStorageSync support for INDEXEDDB #111

Open
audhit opened this issue Dec 30, 2024 · 11 comments
Open

withStorageSync support for INDEXEDDB #111

audhit opened this issue Dec 30, 2024 · 11 comments

Comments

@audhit
Copy link

audhit commented Dec 30, 2024

withStorageSync is working and a cool feature, thanks a lot for it, but I would love to see the support for indexeddb as well because it has more storage limitation compare to 5 MB of localstorage. Please let me know, how can I achieve it. I really want the storage to be indexeddb instead of localstorage or sessionstorage. Thanks in advance.

@rainerhahnekamp
Copy link
Collaborator

You can add a PR. If you are quick, it might land in the 19 release (which is overdue)

@audhit
Copy link
Author

audhit commented Dec 30, 2024

thanks @rainerhahnekamp , is there any 3rd party tool which can provide storage persistence with indexeddb? Please let me know, thanks :)

@rainerhahnekamp
Copy link
Collaborator

@audhit I only know https://dexie.org/

@audhit
Copy link
Author

audhit commented Jan 14, 2025

@rainerhahnekamp do we now have the support for indexedDB storage instead of localStorage/sessionStorage in the latest version v19.0.2 or it is still under development? Please let us know, thanks in advance for the great library...keep rocking 🚀

@rainerhahnekamp
Copy link
Collaborator

Not yet, but nobody prevents us from adding it. I was waiting for further input from the community about the recommended tooling. I don't have a problem with dexie but would know if it is still the library to use.

@audhit
Copy link
Author

audhit commented Jan 14, 2025

https://dexie.org/ looks really good, is it possible to create a wrapper out of dexie and connect it with storageSync API just like below to make it as simple as possible, hoping for the best

  withStorageSync<User>({
    storage: () => dexie,  // rest of the things will be taken care automatically by the library without much extra configs maybe 
  })
);`

@mzkmnk
Copy link

mzkmnk commented Jan 17, 2025

Would @audhit like to add a PR?

@rainerhahnekamp
Copy link
Collaborator

@audhit or @mzkmnk or both: You can give it a try. The only design requirement that I have, is that it needs to be treeshakable. We only want to have dexie as requirement if the user wants to use it.

Therefore:

  • The syntax should be withStorageSync({}, withDexie()) (as it is in withDevtools)
  • withDexie needs to be a secondary entrypoint (look at the redux connector as example)

@rainerhahnekamp
Copy link
Collaborator

@mzkmnk and @audhit

I read through the docs of Dexie and IndexedDB. For simple state synchronisation, I think Dexie is an overkill since it allows more database-related functionality.

We actually just want to persist the data and don't run specific queries. So instead of withDexie(), it could be just withIndexedDb().

What do you think?

@mzkmnk
Copy link

mzkmnk commented Jan 18, 2025

@rainerhahnekamp
I actually thought so too. Using DexieDB in this case would be clearly overkill and might cause us to lose sight of our goal. Therefore, I am planning to implement the save and read functionalities for IndexedDB. How does this look to you?

import { IndexedDB, withStorageSync } from '@angular-architects/ngrx-toolkit';
...
withStorageSync({
   key: 'todos',
   storage: () => IndexedDB,
}),

appendix
Since IndexedDB is asynchronous, there’s some room for consideration.. :)
How about creating a new withIndexedDBSync function instead of integrating IndexedDB into withStorageSync?

appendix2 : )
#129
In this PR, I created a sample code for withIndexedDBSync. It seems promising as it could be simpler than integrating it into the current withStorageSync. What do you think?

@audhit
Copy link
Author

audhit commented Jan 20, 2025

Hey guys, sorry I was away for some time. Looks like @mzkmnk is already working on it here - #129 . Looking forward to it. @rainerhahnekamp please let me know when it is available and which version to install of ngrx-toolkit in order to get it in my project. Really superb work and wonderful toolkit and community. You guys are really helping me out here. Thanks a lot. Cheers :)

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

3 participants