Created
November 9, 2020 12:49
-
-
Save gersona/54aa08c8f9ba22910c12141471800e48 to your computer and use it in GitHub Desktop.
cando proficiency thing
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 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