-
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.
Challenge and Code: Guess Redux Logic and Component
- Loading branch information
Showing
6 changed files
with
59 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { SET_GUESS } from './types'; | ||
|
||
export const setGuessEven = () => { | ||
return { type: SET_GUESS, guess: 'even' }; | ||
} | ||
|
||
export const setGuessOdd = () => { | ||
return { type: SET_GUESS, guess: 'odd' }; | ||
} |
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,27 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { setGuessEven, setGuessOdd } from '../actions/guess'; | ||
|
||
const Guess = ({ guess, setGuessEven, setGuessOdd}) => { | ||
return ( | ||
<div> | ||
<h3>Will it be even or odd?</h3> | ||
<div> | ||
<button | ||
onClick={setGuessEven} | ||
style={guess === 'even' ? { border: '2px solid #43a047' } : null} | ||
>Even</button> | ||
{' '} | ||
<button | ||
onClick={setGuessOdd} | ||
style={guess === 'odd' ? { border: '2px solid #43a047' } : null} | ||
>Odd</button> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default connect( | ||
({ gameState: { guess }}) => ({ guess }), | ||
{ setGuessEven, setGuessOdd } | ||
)(Guess); |
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,16 @@ | ||
import { SET_GUESS, SET_GAME_STARTED } from '../actions/types'; | ||
|
||
const DEFAULT_GAME_STATE = { guess: '' }; | ||
|
||
const gameStateReducer = (state = DEFAULT_GAME_STATE, action) => { | ||
switch(action.type) { | ||
case SET_GUESS: | ||
return { ...state, guess: action.guess }; | ||
case SET_GAME_STARTED: | ||
return DEFAULT_GAME_STATE; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default gameStateReducer; |
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,7 +1,9 @@ | ||
import settingsReducer from './settings'; | ||
import deckReducer from './deck'; | ||
import gameStateReducer from './gameState'; | ||
|
||
export default { | ||
deck: deckReducer, | ||
settings: settingsReducer | ||
settings: settingsReducer, | ||
gameState: gameStateReducer | ||
}; |