Skip to content

Instantly share code, notes, and snippets.

@acacha
Created April 16, 2018 15:58
Show Gist options
  • Save acacha/6cca62937a369ea12912e82048a7bdbe to your computer and use it in GitHub Desktop.
Save acacha/6cca62937a369ea12912e82048a7bdbe to your computer and use it in GitHub Desktop.
import * as mutations from '../../mutation-types'
import * as actions from '../../action-types'
import users from '../../../api/users'
export default {
[ actions.SELECTED_USER ] (context, user) {
context.commit(mutations.SELECTED_USER, user)
},
[ actions.FETCH_USERS ] (context) {
return new Promise((resolve, reject) => {
users.fetch().then(response => {
context.commit(mutations.SET_USERS, response.data)
resolve(response)
}).catch(error => {
reject(error)
})
})
},
[ actions.UPDATE_USER ] (context, user) {
return new Promise((resolve, reject) => {
users.update(user).then(response => {
context.commit(mutations.USER, user)
resolve(response)
}).catch(error => {
reject(error)
})
})
}
}
export default {
selectedUser: state => state.selected_user,
users: state => state.users
}
import getters from './getters'
import actions from './actions'
import mutations from './mutations'
const state = {
selected_user: {},
users: []
}
export default {
state,
getters,
actions,
mutations
}
import * as types from '../../mutation-types'
export default {
[ types.SELECTED_USER ] (state, user) {
state.selected_user = user
},
[ types.SET_USERS ] (state, users) {
state.users = users
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment