Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Conversation

nelsliu9121
Copy link
Contributor

This PR adds rehydrated callback after store.replaceState has been called.

P.S. Why does it seem like nobody actually uses prettier to format the code?

@robinvdvleuten
Copy link
Owner

Thanks for the PR. Could you remove the changes you've done by "fixing" prettier? Now it's quite hard to see the actual change you've made with all the indentation changes. The prettier config was just fine, nothing needed to be changed there.

@robinvdvleuten
Copy link
Owner

Could you please elaborate the purpose of the callback? And the option is also missing in the README.

@nelsliu9121
Copy link
Contributor Author

The thing I am trying to achieve here is mainly targeted to Nuxt.js users.

Since Nuxt.js users would have to implement window.onNuxtReady() to make the persisted state from localStorage to work, there is a slight time gap between when Nuxt is ready and when persisted state is re-hydrated.

Therefore, if one wishes to access data that is stored in Vuex during the mounted lifecycle, one would get a Nuxt re-hydrated value, instead of the localStorage persisted value.

By providing a rehydrated callback, users can commit a mutation to the store, changing a stored value, say isLoaded, to true, which can be a signal that indicates the state has been retrieved from localStorage.

I hope that I have explained my motive to implement this. I will make changes to the README file later.

@ruicky
Copy link

ruicky commented Jul 18, 2019

@nelsliu9121 rehydrated isLoaded Can you tell me how to use in NuxtJs?
I encountered problems during use. When i use plugins read store state, it's empty . Because load data after window.onNuxtReady()
so i want to know When is it loaded before reading the data?
Can you give me some examples?
Thank you very much.

@firstaml-dima
Copy link

Awesome! I'd like to see this merged.

@aezur
Copy link

aezur commented Oct 6, 2019

Another usecase is when using navigation guards for authentication and redirection in Vue. The beforeEnter guards need a way to know when rehydration is finished so it knows when it's safe to check.

@aariacarterweir
Copy link

Any reason this hasn't been merged in yet?

@ramonakira
Copy link

I also need this functionality to be able to use this package.

@robinvdvleuten robinvdvleuten merged commit ac20b27 into robinvdvleuten:master Oct 30, 2019
@robinvdvleuten
Copy link
Owner

@nelsliu9121 thanks for your work!

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

Successfully merging this pull request may close these issues.

7 participants