ngxs-labs / async-storage-plugin

⏱ WIP: Async Storage Plugin
MIT License
34 stars 14 forks source link

init storage engine before ngxs starts #162

Open pentabarf opened 3 years ago

pentabarf commented 3 years ago

Hello,

I am trying to use the async-storage-plugin together with cordova-sqlite-storage. The Storage Engine needs to get initialized (open DB etc.) Where is the right place to do this? AsyncStoragePlugin always wants to access before the DB is available. I was trying to init the DB with angular APP_INITIALIZER but this gets triggered after Ngxs init routines.

pentabarf commented 3 years ago

I also tried to use ngxsOnInit hook. but when using AsyncStoragePlugin ngxsOnInit never gets called. But it gets called when i disable AsyncStoragePlugin

thmclellan commented 3 years ago

Maybe too late, but I tried initializing ionic storage (2.x) in the angular APP_INITIALIZER (with blocking to wait until ionic storage was ready). My app.module.ts included:

NgxsModule.forRoot([], { developmentMode }), NgxsAsyncStoragePluginModule.forRoot(CustomStorageService),

And then I loaded all of my states in a child module (core.module.ts):

NgxsModule.forFeature([ AccountState, UserState...])

This has been working on Ionic 4 / Capacitor 2 for iOS, Android, and web.