Skip to content

Commit

Permalink
Using mapMutations in TaskList
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumebriday committed Jun 7, 2018
1 parent 9153ddb commit 10a6e35
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/js/components/Tasks/TaskList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import Navbar from '@components/Navbar'
import Task from '@components/Tasks/Task'
import TaskForm from '@components/Tasks/TaskForm'
import { mapGetters } from 'vuex'
import { mapGetters, mapMutations } from 'vuex'
export default {
components: {
Expand Down Expand Up @@ -99,21 +99,13 @@ export default {
}
},
created () {
this.getTasks()
if (window.Echo) {
let userId = window.localStorage.getItem('userId')
window.Echo.private(`App.User.${userId}`)
.listen('TaskCreated', e => this.$store.commit('addTask', e.task))
.listen('TaskUpdated', e => this.$store.commit('updateTask', e.task))
.listen('TaskDeleted', e => this.$store.commit('removeTask', e.task))
.listen('TasksDeleted', e => this.tasksDeleted())
}
},
methods: {
...mapMutations([
'addTask',
'updateTask',
'removeTask'
]),
getTasks () {
this.isLoading = true
Expand All @@ -137,7 +129,21 @@ export default {
},
tasksDeleted () {
this.completedTasks.forEach(task => this.$store.commit('removeTask', task))
this.completedTasks.forEach(task => this.removeTask(task))
}
},
created () {
this.getTasks()
if (window.Echo) {
let userId = window.localStorage.getItem('userId')
window.Echo.private(`App.User.${userId}`)
.listen('TaskCreated', e => this.addTask(e.task))
.listen('TaskUpdated', e => this.updateTask(e.task))
.listen('TaskDeleted', e => this.removeTask(e.task))
.listen('TasksDeleted', e => this.tasksDeleted())
}
}
}
Expand Down

0 comments on commit 10a6e35

Please sign in to comment.