]> git.cworth.org Git - lmno.games/commitdiff
Avoid some repeated references to "this.type"
authorCarl Worth <cworth@cworth.org>
Fri, 5 Jun 2020 18:03:08 +0000 (11:03 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 6 Jun 2020 11:46:51 +0000 (04:46 -0700)
Simpler to just cache this is "state" at the beginning of the function
and then use that throughout.

tictactoe/tictactoe.jsx

index f5951f1ff26a4bb738dd26a13c74f13feed08ccf..326a5dd4740b0d465a94ab39296e5c5192feed79 100644 (file)
@@ -253,28 +253,29 @@ class Game extends React.Component {
   }
 
   render() {
   }
 
   render() {
-    const history = this.state.history;
-    const current = history[this.state.step_number];
+    const state = this.state;
+    const history = state.history;
+    const current = history[state.step_number];
     const winner = calculate_winner(current.squares);
 
     let status;
     if (winner) {
       status = "Winner: " + winner;
     } else {
     const winner = calculate_winner(current.squares);
 
     let status;
     if (winner) {
       status = "Winner: " + winner;
     } else {
-      status = "Next player: " + (Team.properties[this.state.next_to_play].name);
+      status = "Next player: " + (Team.properties[state.next_to_play].name);
     }
 
     return [
       <GameInfo
         key="game-info"
     }
 
     return [
       <GameInfo
         key="game-info"
-        id={this.state.game_info.id}
-        url={this.state.game_info.url}
+        id={state.game_info.id}
+        url={state.game_info.url}
       />,
       <PlayerInfo
         key="player-info"
       />,
       <PlayerInfo
         key="player-info"
-        id={this.state.player_info.id}
-        name={this.state.player_info.name}
-        team={this.state.player_info.team}
+        id={state.player_info.id}
+        name={state.player_info.name}
+        team={state.player_info.team}
       />,
       <div key="game" className="game">
         <button className="inline"
       />,
       <div key="game" className="game">
         <button className="inline"