Skip to content
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

#1591 refactor: do not mutate mutation payload in the todo app example #1670

Merged
merged 2 commits into from
Jan 27, 2020

Conversation

kiaking
Copy link
Member

@kiaking kiaking commented Jan 27, 2020

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.

@kiaking kiaking requested a review from ktsn January 27, 2020 15:21
@kiaking kiaking self-assigned this Jan 27, 2020
@kiaking
Copy link
Member Author

kiaking commented Jan 27, 2020

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.

@kiaking
Copy link
Member Author

kiaking commented Jan 27, 2020

OK now test is passing.

@@ -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 })
Copy link
Member

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.

Suggested change
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
})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah of course 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

@ktsn ktsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ktsn ktsn merged commit bafa881 into dev Jan 27, 2020
@kiaking kiaking deleted the 1591-refactor-todo-example branch January 27, 2020 16:09
vaga pushed a commit to vaga/vuex that referenced this pull request Apr 20, 2020
…js#1670)

* refactor: do not mutate mutation payload in the todo app example

* refactor: make things a bit easier to read
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants