Sfoglia il codice sorgente

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
Kia King Ishii 5 anni fa
parent
commit
bafa8817da
1 ha cambiato i file con 7 aggiunte e 2 eliminazioni
  1. 7 2
      examples/todomvc/store/mutations.js

+ 7 - 2
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
+    })
   }
 }