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

localForage support #3

Closed
invernizzi opened this issue Aug 16, 2017 · 13 comments
Closed

localForage support #3

invernizzi opened this issue Aug 16, 2017 · 13 comments
Assignees

Comments

@invernizzi
Copy link

Hi Arnav,
first of all, thank you for releasing vuex-persist.
You mention on your readme that localforage is supported.
However, new VuexPersistance(storage: localforage}) doesn't work - it surfaces an error related to localforage being asynchronous (VuexPersistance is trying to JSON decode a JS promise).
Any tip how to make this work?

@championswimmer
Copy link
Owner

Ah, will have to make some changes for that. Let me add this to my todo.

@sandrooco
Copy link

Same problem here.
@championswimmer Do you think you can implement support for this shortly? This package is great and really does everything a indexeddb vuex plugin should do. Although I have very limited experience with offline stuff, let me know if I can help with anything.

@agonzalezml
Copy link

I'm also interested in this! It seems the best way of enhancing this awesome package.

@championswimmer
Copy link
Owner

So I will make restoreState and saveState async functions (change their signatures to (): Promise )
I have a Vue project to work on this weekend, and it will require some vuex-persist help, I'll improve upon 2-3 things, including this localForage support then.

@Tronix117
Copy link

Any news about that ?

@RichiCoder1
Copy link
Contributor

If yah don't get around to it, will probably tackle this too @championswimmer :)

@gijo-varghese
Copy link

@championswimmer can I expect it soon?

@wopian
Copy link

wopian commented Nov 7, 2017

0.4.0 / 2170a51 adds support for IndexedDB/localforage


Edit: @gijo-varghese, as vuex-persist JSON parses the state, you'll need to override these functions to avoid this (IndexedDB works with objects directly)

new VuexPersistance({
  storage: localforage,
  saveState: (key, state, storage) => Promise.resolve(storage.setItem(key, state)),
  restoreState: (key, storage) => Promise.resolve(storage.getItem(key))
})

@championswimmer
Copy link
Owner

@gijo-varghese use v0.5.0

You simple need to use

new VuexPersistence({
    storage: localforage
})

@to-svarghese
Copy link

Is localForage is ready to work with vuex-persist?

I tried to use localforage for storing dala loacally and to work offline. When I use localforage with vuex-persist data is storing and when I refresh the page all data stored is lost and is reset to initial values. What could be the reason? But it is working when I change that to localstorage.

@TimonPost
Copy link

I am experiencing the same, have you found the reason?

@ulf1
Copy link

ulf1 commented Aug 28, 2020

@TimonPost @to-svarghese
I had the same symptom rn.
this helped: #117 (comment)

example:

import VuexPersist from 'vuex-persist';
import localForage from 'localforage'
const vuexStorage = new VuexPersist({
  ...
  storage: localForage,
  asyncStorage: true, // <<< ADD THIS
  ...
});

This should probably set as default value when VuexPersist detected that storage is localForage. @championswimmer

@yeus
Copy link

yeus commented Dec 31, 2020

  asyncStorage: true, // <<< ADD THIS

this worked!, thx @ulf1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests