-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Modules states can't be overwritten in their entirety #82
Comments
State is an argument, which is just a local variable inside the function, assigning it to something else obviously won't work, that's how javascript works. The gist is that instead of replacing it like that, you should always treat the state as an irreplaceable root and hold actual state as properties under it. |
Well explained, thanks – sorry to bring up a non-issue. |
I'm wondering what the best practice would be when trying to achieve this? [SET_FILE_SYSTEM]: (state, details) => {
emptyObjects(state, details)
mergeObjects(state, details)
} But I have a felling this isn't exatly a best practice... |
Better late than sorry... just as a reference. Overwrite whole store with response data: SET_COMMENTS (state, response) {
Object.assign(state, response)
} |
A couple things at once here, sorry. Hopefully I'm posting this in the correct location, apologies if not – I'm not a seasoned github user.
This is best shown by example. The following code, which is a module in my vuex store, doesn't work as expected (i.e. the changes aren't tracked by vue).
Note: this module is called "comments", the state variable in the mutation is named comments just because that's exactly what it is.
If I were to change this to comments.all = data.comments it would work, but just assigning this top level variable itself doesn't.
[Updated]: Clarified the situation a bit better.
The text was updated successfully, but these errors were encountered: