Skip to content

Instantly share code, notes, and snippets.

@gersona
Created November 9, 2020 12:49
Show Gist options
  • Save gersona/54aa08c8f9ba22910c12141471800e48 to your computer and use it in GitHub Desktop.
Save gersona/54aa08c8f9ba22910c12141471800e48 to your computer and use it in GitHub Desktop.
cando proficiency thing
export const state = () => ({
candos = [
{id: 1, text: 'cando one', proficiency: '3'},
{id: 2, text: 'cando two', proficiency: '1'},
{id: 3, text: 'cando three', proficiency: '2'},
]
})
export const getters = {
allProficiencies: (state) => {
let allProficiencies = state.candos.forEach(cando => {
return { id: cando.id, proficiency: cando.proficiency }
})
return allProficiencies
}
}
export const mutations = {
setProficiency: (state, {id, value}) => {
let idx = state.candos.findIndex(e => e.id === id)
if (idx !== -1) {
candos[idx].proficiency = value
}
}
}
export const actions = {
async fetchproficiencies(context) {
let data = manaoAPICall() // [{id: 2, proficiency: 1 }, ...]
data.forEach(element => {
context.commit('setProficiency', element)
});
},
async updateProficiencyIndividual(context, element){
context.commit('setProficiency', element)
},
async updateProficiencies(context) {
updateProficiencyAPICall(context.getters.allProficiencies) // manao API call any @ backend
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment