From d1285125f5412ce9ca814cef21797ab8e666b3af Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 15 Sep 2020 07:22:30 -0500 Subject: [PATCH] add set/merge character mutations with data to Vuex --- client/src/mutation_types.js | 5 +++-- client/src/store.js | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/client/src/mutation_types.js b/client/src/mutation_types.js index a86191b..7a81e1b 100644 --- a/client/src/mutation_types.js +++ b/client/src/mutation_types.js @@ -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' } diff --git a/client/src/store.js b/client/src/store.js index d6a0bda..d77cf5a 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -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