Skip to content

Commit

Permalink
Clean up store
Browse files Browse the repository at this point in the history
  • Loading branch information
cy-by committed Jan 22, 2020
1 parent 319c244 commit 017d93e
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,9 @@ import Vuex from 'vuex';

Vue.use(Vuex);

// Status:
// idle
// fetchDeck
// first
// compare
// win
// error

export default new Vuex.Store({
state: {
cards: null,
cardsLeft: null,
firstCard: null,
secondCard: null,
status: 'idle',
Expand All @@ -40,8 +31,6 @@ export default new Vuex.Store({
commit('updateStatus', 'compare');

if (firstCard.name === secondCard.name) {
// TODO: success! give feedback

// Update cards
const copy = [...cards];
const firstIndex = cards.findIndex(card => card.uuid === firstCard.uuid);
Expand All @@ -58,7 +47,7 @@ export default new Vuex.Store({
commit('updateSecondCard', null);

if (getters.getUnMatchedCards && getters.getUnMatchedCards.length === 0) {
commit('updateStatus', 'win');
commit('updateStatus', 'won');
} else {
commit('updateStatus', 'idle');
}
Expand Down Expand Up @@ -100,10 +89,11 @@ export default new Vuex.Store({
}

commit('updateSecondCard', card);
commit('updateStatus', 'wait');

setTimeout(() => {
dispatch('compareCards');
}, 1000);
}, 600);
}
},
shuffleDeck({ commit, state }) {
Expand All @@ -128,15 +118,9 @@ export default new Vuex.Store({
getCards(state) {
return state.cards;
},
getCardsLeft(state) {
return state.cardsLeft;
},
getFirstCard(state) {
return state.firstCard;
},
getMatchedCards(state) {
return state.cards && state.cards.filter(card => card.isMatched === true);
},
getSecondCard(state) {
return state.secondCard;
},
Expand Down

0 comments on commit 017d93e

Please sign in to comment.