Skip to content

Instantly share code, notes, and snippets.

@chl03ks
Created June 11, 2018 17:02
Show Gist options
  • Save chl03ks/93da427266f7ded7593a1fd15f7692a2 to your computer and use it in GitHub Desktop.
Save chl03ks/93da427266f7ded7593a1fd15f7692a2 to your computer and use it in GitHub Desktop.
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