i have question about state managment in vue/vuex
- i use 'nuxt-vuex-localstorage' for persistence
- i divided my store into modules like 'ui', 'user'
The problem is that when in one action i dispatch two store actions like
const res = await API_CALL('someEndpoint')
this.$store.dispatch('ui/setSignInVisible', false)
this.$store.dispatch('customer/setToken', res.token)
this gives me errors because first i get setSignInVisible to false, but this next acion set it to true. I assume this happened because localStorage operation is async.
this solve this issue:
const res = await API_CALL('someEndpoint')
await this.$store.dispatch('ui/setSignInVisible', false)
this.$store.dispatch('customer/setToken', res.token)
But my question is, should this work this way, or there is some better approach to manage state. Approach in which i will not worry about of overriding state.