async-storage-plugin icon indicating copy to clipboard operation
async-storage-plugin copied to clipboard

init storage engine before ngxs starts

Open pentabarf opened this issue 4 years ago • 2 comments

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 avatar Mar 29 '21 08:03 pentabarf

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

pentabarf avatar Mar 29 '21 09:03 pentabarf

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.

thmclellan avatar Jul 20 '21 15:07 thmclellan