acammies
2018-04-04 1f415e2892158066c2fd16c6698383427f1a203c
commit | author | age
82de6c 1 export default {
D 2   SET_LOADING(state, bool) {
3     state.loading = bool;
4   },
5   SET_TODOS(state, todos) {
6     state.todos = todos;
7   },
8   SET_NEW_TODO(state, todo) {
1f415e 9     // debugger
82de6c 10     state.newTodo = todo;
D 11   },
12   ADD_TODO(state, todo) {
13     console.log('INFO - add todo', todo);
14     state.todos.push(todo);
15   },
16   REMOVE_TODO(state, todo) {
17     var todos = state.todos;
18     todos.splice(todos.indexOf(todo), 1);
19   },
20   CLEAR_NEW_TODO(state) {
21     state.newTodo = '';
22     console.log('INFO - clearing new todo');
fbee7b 23   },
08cb74 24   CLEAR_ALL_DONE_TODOS(state) {
A 25     state.todos = state.todos.filter(obj => obj.complete === false);
26   },
fbee7b 27   CLEAR_ALL_TODOS(state) {
08cb74 28     state.todos = [
A 29       // { title: "", id: "0", complete: false, important: false }
30     ];
fbee7b 31     console.log('INFO - clearing all todos');
08cb74 32   },
1f415e 33   UPDATE_TODO(state, updatedTodos) {
A 34     debugger
35     // state.todos.map((obj => ((obj.id !== todo.id )|| todo)));
36     // const foundIndex = state.todos.findIndex(obj => (obj.id === todo.id ));
37     // state.todos[foundIndex] = todo;
38     state.todos = updatedTodos;
39     // don't do this, maybe google instead
40
41
08cb74 42     console.log('INFO - update a todo');
A 43     // state.todos.find(eachTodo => eachTodo.id === todo.id)
44     // arr1.map(obj => arr2.find(o => o.id === obj.id) || obj);
45
46
47     // take a current todo, change one of its parameters, update todo.
48     // state.todos.find(todo);
49       // myArray.find(x => x.id === '45')
50     // set state.todos.oldTodo = newTodo
51     
82de6c 52   }
D 53 };