Skip to content

Commit 1d23358

Browse files
committed
Rename handler functions
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.
1 parent a4a963b commit 1d23358

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/board.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var Board = React.createClass({
44
propTypes: {
5-
endGame: React.PropTypes.func.isRequired,
5+
onGameFinished: React.PropTypes.func.isRequired,
66
max: React.PropTypes.number.isRequired,
77
tiles: React.PropTypes.arrayOf(React.PropTypes.string).isRequired,
88
},
@@ -14,7 +14,7 @@ var Board = React.createClass({
1414
};
1515
},
1616

17-
clickedTile(tile){
17+
onTileClicked(tile){
1818
if (this.wait) {
1919
return;
2020
}
@@ -42,7 +42,7 @@ var Board = React.createClass({
4242
setTimeout(
4343
() => {
4444
this.wait = false;
45-
this.setState({found: this.state.found,message: 'choosetile'});
45+
this.setState({found: this.state.found, message: 'choosetile'});
4646
delete this.flippedtile;
4747
},
4848
2000
@@ -52,7 +52,7 @@ var Board = React.createClass({
5252
render() {
5353
return (
5454
<div>
55-
<button onClick={this.props.endGame}>
55+
<button onClick={this.props.onGameFinished}>
5656
End game
5757
</button>
5858
<Status
@@ -61,7 +61,7 @@ var Board = React.createClass({
6161
message={this.state.message}
6262
/>
6363
{this.props.tiles.map(
64-
(b, n) => <Tile word={b} key={n} clickedTile={this.clickedTile} />
64+
(b, n) => <Tile word={b} key={n} onClick={this.onTileClicked} />
6565
)}
6666
</div>
6767
);

src/game.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ var Game = React.createClass({
1212
});
1313
},
1414

15-
endGame() {
15+
reset() {
1616
this.setState({playing: false});
1717
},
1818

1919
render() {
2020
return this.state.playing ? (
2121
<Board
22-
endGame={this.endGame}
22+
onGameFinished={this.reset}
2323
tiles={this.state.tiles}
2424
max={this.state.tiles.length / 2}
2525
/>
2626
) : (
27-
<Wordform startGame={this.startGame} />
27+
<Wordform onWordsEntered={this.startGame} />
2828
);
2929
}
3030
});

src/tile.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var Tile = React.createClass({
44
propTypes: {
55
word: React.PropTypes.string.isRequired,
6-
clickedTile: React.PropTypes.func.isRequired,
6+
onClick: React.PropTypes.func.isRequired,
77
},
88

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

1313
catchClick() {
1414
if (!this.state.flipped) {
15-
this.props.clickedTile(this);
15+
this.props.onClick(this);
1616
}
1717
},
1818

src/wordform.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var Wordform = React.createClass({
44
propTypes: {
5-
startGame: React.PropTypes.func.isRequired,
5+
onWordsEntered: React.PropTypes.func.isRequired,
66
},
77

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

0 commit comments

Comments
 (0)