-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
#1591 refactor: do not mutate mutation payload in the todo app example #1670
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
Conversation
Hmmm... test is failing. It passes at local env so it might be timing issue... We should look into the e2e test to be more stable. |
36300c1
to
cce1519
Compare
OK now test is passing. |
examples/todomvc/store/mutations.js
Outdated
@@ -15,7 +15,6 @@ export const mutations = { | |||
}, | |||
|
|||
editTodo (state, { todo, text = todo.text, done = todo.done }) { | |||
todo.text = text | |||
todo.done = done | |||
state.todos.splice(state.todos.indexOf(todo), 1, { ...todo, text, done }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we refactor it for readability? Having everything on one line looks a bit too packed.
state.todos.splice(state.todos.indexOf(todo), 1, { ...todo, text, done }) | |
const index = state.todos.indexOf(todo) | |
state.todos.splice(index, 1, { | |
...todo, | |
text, | |
done | |
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah of course 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
…js#1670) * refactor: do not mutate mutation payload in the todo app example * refactor: make things a bit easier to read
Issue #1591
This PR refactors the mutation logic in todo example to not mutate mutation payload directly in the simplest form.
It's still using the reference to todo (at
indexOf
) but I think it's more clearer than before that Vuex recommends to not mutate payload directly.