Created
June 11, 2018 17:02
-
-
Save chl03ks/93da427266f7ded7593a1fd15f7692a2 to your computer and use it in GitHub Desktop.
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
const players = (state = [{ id: 1, level: 10 }], action) => { | |
if (action.type === 'LEVEL_UP') { | |
return state.map(player => { | |
if(player.id !== action.id) return state; | |
return { ...player, level: player.level + 1 } | |
}) | |
} else if (action.type === 'LEVEL_DOWN') { | |
return state.map(player => { | |
if(player.id !== action.id) return state; | |
return { ...player, level: player.level - 1 } | |
}) | |
} else { | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment