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