]> git.cworth.org Git - lmno.games/blobdiff - tictactoe/tictactoe.jsx
Avoid some repeated references to "this.type"
[lmno.games] / tictactoe / tictactoe.jsx
index f1426ecff4f443c8837237fffd8caeef3f751153..326a5dd4740b0d465a94ab39296e5c5192feed79 100644 (file)
@@ -72,6 +72,9 @@ events.addEventListener("game-state", event => {
  *********************************************************/
 
 function GameInfo(props) {
+  if (! props.id)
+    return null;
+
   return (
     <div className="game-info">
       <h2>{props.id}</h2>
@@ -81,10 +84,14 @@ function GameInfo(props) {
 }
 
 function PlayerInfo(props) {
+  if (! props.id)
+    return null;
+
   return (
     <div className="player-info">
       <h2>Player</h2>
-      {props.name}, ID: {props.id}, on team: {props.team}
+      {props.name}, ID: {props.id},
+      {props.team ? ` on team ${props.team}` : " not on a team"}
     </div>
   );
 }
@@ -246,28 +253,29 @@ class Game extends React.Component {
   }
 
   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 {
-      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"
-        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"
-        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"