My Vue application uses a Vuex store. Sometimes the user can "reset" the session. This entails resetting the vuex store to the default values and so that ANY pending async operations should be dropped because the Vuex store has been reset. The issue is that when the async calls return, they attempt to modify the store but it has since been reset. How can I force ANY pending async operation to be ignored when the user hits "reset".
I thought of recalling the "createStore" Vuex function but this lead to a dead-end because the global store variable is updated.
Edit: I end up passing a StoreID with EVERY mutation. I store this StoreID value in a variable at the beginning of all my async ACTIONS. The mutation verifies when it's called that the store currently is at the same StoreID version. Is there a more clever way to do this?
You could move the StoreID check to the request layer before you resolve / reject the request promise. If the StoreID has changed since the request was made, ignore the result by not calling resolve or reject. This will allow you to remove the check from the rest of your store as the mutations will never be called for requests sent before you updated the StoreID.
Another option if you are using axios or something that has the ability to cancel requests is to save all pending request cancellation tokens in an array and cancel them all when you are resetting your store. A gotcha here is that you will need to check in your request error handling if the reason your request was rejected is because it was canceled.