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

Async Storage with localForage .restored not available. #174

Open
WesleyBuck opened this issue Mar 3, 2020 · 6 comments
Open

Async Storage with localForage .restored not available. #174

WesleyBuck opened this issue Mar 3, 2020 · 6 comments

Comments

@WesleyBuck
Copy link

WesleyBuck commented Mar 3, 2020

Currently, we have an older project that we are migrating from javascript to typescript. Implemented typescript router but still using javascript store.
Tried npm install @types/vuex-persist with no such package available.

Ended up adding vuex-persist.d.ts, which solved the problem:

import Vue, { VNode } from 'vue'
 import { Store } from 'vuex'
 
declare module 'vuex' {
    export interface Store<S> {
         restored: Promise<S>
     }
}

Is there a possibility to include types for future users that may experience the same problem?

@BasNijhuis
Copy link

Same issue here, temporary fixed it like so:

// hacky solution since type declartion for restored is missing in vuex-persist
// waits for IndexedDB (localForage) to be loaded into vuex so mutations aren't overridden on start up
await ((store as unknown) as { restored: Promise<unknown> }).restored;

@TimonPost
Copy link

Use this workaround which worked for me: #15 (comment)

@rinux55
Copy link

rinux55 commented May 22, 2020

running into the same issue. the restored prop is not available... unable to use the suggested solutions above.

@rinux55
Copy link

rinux55 commented May 22, 2020

alright the solution is to provide asyncStorage: true in the constructor options. This was not clear from the docs in the section 'notes on localForage'...

@jacobcoro
Copy link

Same issue for me, solved with @BasNijhuis solution plus @rinux55 solution. PLEASE ADD TO DOCS!

@jacobcoro
Copy link

This stopped working for some reason, but I got it back by doing

await (store as any).original.restored;
in my router guard

and restoreState: key => localForage.getItem(key),
in const vuexLocalForage = new VuexPersistence<RootState>({

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

5 participants