Skip to content

Instantly share code, notes, and snippets.

View anoobbava's full-sized avatar
🎯
Focusing

Anoob Bava anoobbava

🎯
Focusing
View GitHub Profile
updateTodoMutation (state, todo) {
let index = state.todos.findIndex(element => element.id === todo.id)
state.todos[index] = todo
}
async updateTodo (todo) {
const updatedTodoHash = { is_completed: todo.is_completed }
const response = await axios.put('todos/' + todo.id, updatedTodoHash)
return response.data
}
updateTodoAction ({ commit }, todo) {
return new Promise((resolve, reject) => {
ApiHelper.updateTodo(todo)
.then(response => {
commit('updateTodoMutation', response)
resolve(response)
})
.catch(error => {
reject(error)
})
updateTodo(todo) {
this.updateTodoAction(todo)
.then(() => SweetAlert.successfulLogin())
.catch(() => SweetAlert.failureLogin())
}
@anoobbava
anoobbava / Home.vue
Last active December 16, 2019 13:22
<v-checkbox
v-model="task.is_completed"
color="info darken-3"
@change="updateTodo(task)"
>
saveTodoMutation (state, todo) {
state.todos = [...state.todos, todo]
}
saveTodoAction ({ commit }, todoData) {
return new Promise((resolve, reject) => {
ApiHelper.todo(todoData)
.then(response => {
commit('saveTodoMutation', response)
resolve(response)
})
.catch(error => {
reject(error)
})
createTodo () {
const todoData = { 'title': this.task }
this.saveTodoAction(todoData)
.then(() => {
this.task = ''
SweetAlert.successfulLogin()
})
.catch(() => {
SweetAlert.failureLogin()
})
async todo (todoData) {
const response = await axios.post('todos', todoData)
return response.data
}
@anoobbava
anoobbava / actions.js
Created December 16, 2019 11:29
article
actions: {
fetchAllTodoAction ({ commit }) {
return new Promise((resolve, reject) => {
ApiHelper.todos()
.then(response => {
commit('fetchAllTodoMutation', response)
resolve(response)
})
.catch(error => {
commit('failureTodoMutation')