-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
38 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { DECK } from '../actions/types'; | ||
import fetchStates from './fetchStates'; | ||
|
||
const DEFAULT_DECK = { | ||
deck_id: '', | ||
remaining: 0, | ||
fetchState: '', | ||
message: '' | ||
}; | ||
|
||
const deckReducer = (state = DEFAULT_DECK, action) => { | ||
console.log('state', state, 'action', action); | ||
|
||
switch(action.type) { | ||
case DECK.FETCH_SUCCESS: | ||
const { remaining, deck_id } = action; | ||
|
||
return { ...state, remaining, deck_id, fetchState: fetchStates.success }; | ||
case DECK.FETCH_ERROR: | ||
return { ...state, message: action.message, fetchState: fetchStates.error }; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default deckReducer; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,7 @@ | ||
import { | ||
SET_GAME_STARTED, | ||
SET_INSTRUCTIONS_EXPANDED, | ||
DECK | ||
} from '../actions/types'; | ||
import fetchStates from './fetchStates'; | ||
import settingsReducer from './settings'; | ||
import deckReducer from './deck'; | ||
|
||
const DEFAULT_SETTINGS = { | ||
gameStarted: false, | ||
instructionsExpanded: false | ||
export default { | ||
deck: deckReducer, | ||
settings: settingsReducer | ||
}; | ||
|
||
const rootReducer = (state = DEFAULT_SETTINGS, action) => { | ||
console.log('state', state, 'action', action); | ||
|
||
switch(action.type) { | ||
case SET_GAME_STARTED: | ||
return { | ||
...state, | ||
gameStarted: action.gameStarted | ||
}; | ||
case SET_INSTRUCTIONS_EXPANDED: | ||
return { | ||
...state, | ||
instructionsExpanded: action.instructionsExpanded | ||
}; | ||
case DECK.FETCH_SUCCESS: | ||
const { remaining, deck_id } = action; | ||
|
||
return { ...state, remaining, deck_id, fetchState: fetchStates.success }; | ||
case DECK.FETCH_ERROR: | ||
return { ...state, message: action.message, fetchState: fetchStates.error }; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default rootReducer; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { | ||
SET_GAME_STARTED, | ||
SET_INSTRUCTIONS_EXPANDED | ||
} from '../actions/types'; | ||
import fetchStates from './fetchStates'; | ||
|
||
const DEFAULT_SETTINGS = { | ||
gameStarted: false, | ||
instructionsExpanded: false | ||
}; | ||
|
||
const settingsReducer = (state = DEFAULT_SETTINGS, action) => { | ||
console.log('state', state, 'action', action); | ||
|
||
switch(action.type) { | ||
case SET_GAME_STARTED: | ||
return { | ||
...state, | ||
gameStarted: action.gameStarted | ||
}; | ||
case SET_INSTRUCTIONS_EXPANDED: | ||
return { | ||
...state, | ||
instructionsExpanded: action.instructionsExpanded | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default settingsReducer; |