add set/merge character mutations with data to Vuex

This commit is contained in:
Xevion
2020-09-15 07:22:30 -05:00
parent 04320d15b5
commit d1285125f5
2 changed files with 19 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ export const types = {
SET_EPISODE: 'SET_EPISODE',
MERGE_EPISODE: 'MERGE_EPISODE',
SET_PRELOADED: 'SET_PRELOADED',
PRELOAD: 'PRELOAD'
PRELOAD: 'PRELOAD',
SET_CHARACTER: 'SET_CHARACTER',
MERGE_CHARACTER: 'MERGE_CHARACTER'
}

View File

@@ -21,11 +21,14 @@ export default new Vuex.Store({
episodeCount: episodeCount,
quoteData: baseData,
preloaded: false,
characters: {}
},
mutations: {
// Fully set episode data
[types.SET_EPISODE](state, payload) {
state.quoteData[payload.season - 1].episodes[payload.episode - 1] = payload.data
state.quoteData[payload.season - 1].episodes[payload.episode - 1] = payload.episodeData
},
// 'Merge' episode data, overwriting existing attributes as needed
[types.MERGE_EPISODE](state, payload) {
const s = payload.season - 1;
const e = payload.episode - 1;
@@ -37,7 +40,19 @@ export default new Vuex.Store({
},
[types.SET_PRELOADED](state, status) {
state.preloaded = status;
},
[types.SET_CHARACTER](state, payload) {
state.characters[payload.id] = payload.characterData
}
},
[types.MERGE_CHARACTER](state, payload) {
const id = payload.id;
// If character has not been defined in character list yet, simply set the characterData
if(state.characters[id] === undefined)
state.character[id] = payload.characterData
// Otherwise use intended merge & overwrite effect.
else
state.characters[id] = Object.assign(state.characters[id], payload.characterData)
},
actions: {
// Perform async API call to fetch specific Episode data