Skip to content

Instantly share code, notes, and snippets.

@nicohvi
Last active February 26, 2017 11:23
Show Gist options
  • Save nicohvi/bd4b270de2595d6240bfb6ff96530b19 to your computer and use it in GitHub Desktop.
Save nicohvi/bd4b270de2595d6240bfb6ff96530b19 to your computer and use it in GitHub Desktop.
class PokemonGym extends React.Component {
renderBattle () {
const { trainer } = this.props;
switch(trainer) {
case "Annoying school boy":
return this.schoolBoy();
case "Pretentios nerd":
return this.nerd();
case "Brock":
return this.brock();
default:
console.error(`trainer not found: ${trainer}`);
return null;
}
}
render () {
return <section className="gym-battle">
{this.renderBattle()}
</section>;
}
}
class PokemonGym extends React.Component {
constructor(props) {
super(props);
this.renderBattle = R.cond([
[R.eq('Annoying school boy'), () => <SchoolBoy />],
[R.eq('Pretentios nerd', () => <Nerd />]
[R.eq('brock', () => <Brock />],
[R.T, () => null]
]);
}
render () {
const { trainer } = this.props;
return <section className="gym-battle">
{this.renderBattle(trainer)}
</section>;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment