From 3dfd4d87a6ef4104b63299fa747480cd61075cd0 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Wed, 11 Sep 2019 22:02:05 +0200 Subject: [PATCH] refactor: create some getters in vuex --- client/src/store/modules/ddragon.js | 4 ++++ client/src/store/modules/summoner.js | 18 ++++++++++-------- client/src/views/Summoner.vue | 28 +++++++++++++++------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/client/src/store/modules/ddragon.js b/client/src/store/modules/ddragon.js index 4c9c5f9..15f8794 100644 --- a/client/src/store/modules/ddragon.js +++ b/client/src/store/modules/ddragon.js @@ -20,3 +20,7 @@ export const actions = { commit('PUSH_CHAMPIONS', resp.data.data) } } + +export const getters = { + areChampionsLoaded: state => !!state.champions.Aatrox +} diff --git a/client/src/store/modules/summoner.js b/client/src/store/modules/summoner.js index 00a0e50..4b1982b 100644 --- a/client/src/store/modules/summoner.js +++ b/client/src/store/modules/summoner.js @@ -5,28 +5,24 @@ export const namespaced = true export const state = { infos: [], - loading: false, - summonerFound: false + status: '', } export const mutations = { SUMMONER_REQUEST(state) { - state.loading = true + state.status = 'loading' }, SUMMONER_FOUND(state, infos) { - state.summonerFound = true - state.loading = false state.infos = infos + state.status = 'found' }, SUMMONER_NOT_FOUND(state) { - state.summonerFound = false - state.loading = false + state.status = 'error' } } export const actions = { async summonerRequest({ commit, dispatch, rootState }, { summoner, region }) { - console.log(summoner, region) region = rootState.regionsList[region] commit('SUMMONER_REQUEST') try { @@ -49,3 +45,9 @@ export const actions = { } } } + +export const getters = { + summonerFound: state => state.status === 'found', + summonerNotFound: state => state.status === 'error', + summonerLoading: state => state.status === 'loading', +} diff --git a/client/src/views/Summoner.vue b/client/src/views/Summoner.vue index 153eda7..a3853b7 100644 --- a/client/src/views/Summoner.vue +++ b/client/src/views/Summoner.vue @@ -5,13 +5,13 @@ Accueil + >Home -