Created
April 16, 2018 15:58
-
-
Save acacha/6cca62937a369ea12912e82048a7bdbe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
selectedUser: state => state.selected_user, | |
users: state => state.users | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import getters from './getters' | |
import actions from './actions' | |
import mutations from './mutations' | |
const state = { | |
selected_user: {}, | |
users: [] | |
} | |
export default { | |
state, | |
getters, | |
actions, | |
mutations | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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