Skip to content

Commit

Permalink
Rename handler functions
Browse files Browse the repository at this point in the history
Rename the handler functions to be more decoupled from their parents.
Wordform, for instance, doesn’t care about the game starting; it just
needs to notify its parent when the user has entered valid words.
  • Loading branch information
ianobermiller committed Aug 30, 2014
1 parent a4a963b commit 1d23358
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/board.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var Board = React.createClass({
propTypes: {
endGame: React.PropTypes.func.isRequired,
onGameFinished: React.PropTypes.func.isRequired,
max: React.PropTypes.number.isRequired,
tiles: React.PropTypes.arrayOf(React.PropTypes.string).isRequired,
},
Expand All @@ -14,7 +14,7 @@ var Board = React.createClass({
};
},

clickedTile(tile){
onTileClicked(tile){
if (this.wait) {
return;
}
Expand Down Expand Up @@ -42,7 +42,7 @@ var Board = React.createClass({
setTimeout(
() => {
this.wait = false;
this.setState({found: this.state.found,message: 'choosetile'});
this.setState({found: this.state.found, message: 'choosetile'});
delete this.flippedtile;
},
2000
Expand All @@ -52,7 +52,7 @@ var Board = React.createClass({
render() {
return (
<div>
<button onClick={this.props.endGame}>
<button onClick={this.props.onGameFinished}>
End game
</button>
<Status
Expand All @@ -61,7 +61,7 @@ var Board = React.createClass({
message={this.state.message}
/>
{this.props.tiles.map(
(b, n) => <Tile word={b} key={n} clickedTile={this.clickedTile} />
(b, n) => <Tile word={b} key={n} onClick={this.onTileClicked} />
)}
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions src/game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ var Game = React.createClass({
});
},

endGame() {
reset() {
this.setState({playing: false});
},

render() {
return this.state.playing ? (
<Board
endGame={this.endGame}
onGameFinished={this.reset}
tiles={this.state.tiles}
max={this.state.tiles.length / 2}
/>
) : (
<Wordform startGame={this.startGame} />
<Wordform onWordsEntered={this.startGame} />
);
}
});
4 changes: 2 additions & 2 deletions src/tile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var Tile = React.createClass({
propTypes: {
word: React.PropTypes.string.isRequired,
clickedTile: React.PropTypes.func.isRequired,
onClick: React.PropTypes.func.isRequired,
},

getInitialState() {
Expand All @@ -12,7 +12,7 @@ var Tile = React.createClass({

catchClick() {
if (!this.state.flipped) {
this.props.clickedTile(this);
this.props.onClick(this);
}
},

Expand Down
4 changes: 2 additions & 2 deletions src/wordform.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var Wordform = React.createClass({
propTypes: {
startGame: React.PropTypes.func.isRequired,
onWordsEntered: React.PropTypes.func.isRequired,
},

getInitialState() {
Expand All @@ -27,7 +27,7 @@ var Wordform = React.createClass({
} else if (words.filter(w => w.length > 8).length) {
this.setError('Words should not be longer than 8 characters!');
} else {
this.props.startGame(words);
this.props.onWordsEntered(words);
node.value = "";
}
return false;
Expand Down

0 comments on commit 1d23358

Please sign in to comment.