Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added redux for use of a global state
- Loading branch information
Showing
10 changed files
with
282 additions
and
120 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,10 @@ | ||
export const changeColor = (color, hex) => ({ | ||
type: 'CHANGE_COLOR', | ||
color, | ||
hex | ||
}); | ||
|
||
export const changeAllColors = (colors) => ({ | ||
type: 'CHANGE_ALL_COLORS', | ||
colors | ||
}); |
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,36 @@ | ||
const colorsReducerDefaultState = { | ||
colorOne: '#4ECDC4', | ||
colorTwo: '#A7EEE9', | ||
colorThree: '#FF6B6B', | ||
colorFour: '#FFAAAA', | ||
colorFive: '#FFEB8C', | ||
colorSix: '#FFF4C1', | ||
colorSeven: '#D4D4D4', | ||
colorEight: '#EFF3EF' | ||
}; | ||
|
||
const colorsReducer = (state = colorsReducerDefaultState, action) => { | ||
switch (action.type) { | ||
case 'CHANGE_COLOR': | ||
return { | ||
...state, | ||
[action.color]: action.hex | ||
}; | ||
case 'CHANGE_ALL_COLORS': | ||
return { | ||
// Had to individually set them because object was being sent with prototype inside it | ||
colorOne: action.colors.colorOne, | ||
colorTwo: action.colors.colorTwo, | ||
colorThree: action.colors.colorThree, | ||
colorFour: action.colors.colorFour, | ||
colorFive: action.colors.colorFive, | ||
colorSix: action.colors.colorSix, | ||
colorSeven: action.colors.colorSeven, | ||
colorEight: action.colors.colorEight, | ||
} | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default colorsReducer; |
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 { createStore } from 'redux'; | ||
import colorsReducer from '../reducers/colors'; | ||
|
||
export default () => { | ||
// Create global store | ||
const store = createStore(colorsReducer); | ||
|
||
return store; | ||
}; |
Oops, something went wrong.