From bafa8817da7753f36e4375db49ff56a9a3517808 Mon Sep 17 00:00:00 2001 From: Kia King Ishii Date: Tue, 28 Jan 2020 01:09:46 +0900 Subject: [PATCH] refactor: do not mutate mutation payload in the todo app example (#1670) * refactor: do not mutate mutation payload in the todo app example * refactor: make things a bit easier to read --- examples/todomvc/store/mutations.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/todomvc/store/mutations.js b/examples/todomvc/store/mutations.js index d0be5bca2..f68537b8d 100644 --- a/examples/todomvc/store/mutations.js +++ b/examples/todomvc/store/mutations.js @@ -15,7 +15,12 @@ export const mutations = { }, editTodo (state, { todo, text = todo.text, done = todo.done }) { - todo.text = text - todo.done = done + const index = state.todos.indexOf(todo) + + state.todos.splice(index, 1, { + ...todo, + text, + done + }) } }