Rename several internal names from ICantReadThis to much_better_thanks
authorCarl Worth <cworth@cworth.org>
Thu, 4 Jun 2020 23:40:30 +0000 (16:40 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 4 Jun 2020 23:40:30 +0000 (16:40 -0700)
I'm not entirely sure this is a good idea with the number of library
functions that we're calling that still use camel case, (such as
addEventListener, and perhaps most significantly, onClick), but the
code was even more mixed before, so it's maybe at least more
consistent in its inconsistency now, or something?

tictactoe/tictactoe.jsx

index d462ae14f164f34b74037d4820f919beaa60d3f1..c51727dab72f9f4172f743b2422cdaed037d20cb 100644 (file)
@@ -31,16 +31,16 @@ events.onerror = function(event) {
 events.addEventListener("move", event => {
   const move = JSON.parse(event.data);
 
-  window.game.receiveMove(move);
+  window.game.receive_move(move);
 });
 
 events.addEventListener("game-state", event => {
   const state = JSON.parse(event.data);
 
-  window.game.resetState();
+  window.game.reset_state();
 
   for (let square of state.moves) {
-    window.game.receiveMove(square);
+    window.game.receive_move(square);
   }
 });
 
@@ -64,12 +64,12 @@ function Square(props) {
 }
 
 class Board extends React.Component {
-  renderSquare(i) {
+  render_square(i) {
     const value = this.props.squares[i];
     return (
       <Square
         value={value}
-        active={! this.props.gameOver && ! value}
+        active={! this.props.game_over && ! value}
         onClick={() => this.props.onClick(i)}
       />
     );
@@ -79,19 +79,19 @@ class Board extends React.Component {
     return (
       <div>
         <div className="board-row">
-          {this.renderSquare(0)}
-          {this.renderSquare(1)}
-          {this.renderSquare(2)}
+          {this.render_square(0)}
+          {this.render_square(1)}
+          {this.render_square(2)}
         </div>
         <div className="board-row">
-          {this.renderSquare(3)}
-          {this.renderSquare(4)}
-          {this.renderSquare(5)}
+          {this.render_square(3)}
+          {this.render_square(4)}
+          {this.render_square(5)}
         </div>
         <div className="board-row">
-          {this.renderSquare(6)}
-          {this.renderSquare(7)}
-          {this.renderSquare(8)}
+          {this.render_square(6)}
+          {this.render_square(7)}
+          {this.render_square(8)}
         </div>
       </div>
     );
@@ -123,11 +123,11 @@ class Game extends React.Component {
     };
   }
 
-  sendMove(i) {
+  send_move(i) {
     return fetch_post_json("move", { move: i });
   }
 
-  resetState() {
+  reset_state() {
     this.setState({
       history: [
         {
@@ -139,11 +139,11 @@ class Game extends React.Component {
     });
   }
 
-  receiveMove(i) {
+  receive_move(i) {
     const history = this.state.history.slice(0, this.state.step_number + 1);
     const current = history[history.length - 1];
     const squares = current.squares.slice();
-    if (calculateWinner(squares) || squares[i]) {
+    if (calculate_winner(squares) || squares[i]) {
       return;
     }
     squares[i] = Team.properties[this.state.next_to_play].name;
@@ -163,8 +163,8 @@ class Game extends React.Component {
     });
   }
 
-  async handleClick(i) {
-    const response = await this.sendMove(i);
+  async handle_click(i) {
+    const response = await this.send_move(i);
     if (response.status == 200) {
       const result = await response.json();
       if (! result.legal)
@@ -177,7 +177,7 @@ class Game extends React.Component {
   render() {
     const history = this.state.history;
     const current = history[this.state.step_number];
-    const winner = calculateWinner(current.squares);
+    const winner = calculate_winner(current.squares);
 
     let status;
     if (winner) {
@@ -193,9 +193,9 @@ class Game extends React.Component {
         </div>
         <div className="game-board">
           <Board
-            gameOver={winner}
+            game_over={winner}
             squares={current.squares}
-            onClick={i => this.handleClick(i)}
+            onClick={i => this.handle_click(i)}
           />
         </div>
       </div>
@@ -209,7 +209,7 @@ ReactDOM.render(<Game
                   ref={(me) => window.game = me}
                 />, document.getElementById("tictactoe"));
 
-function calculateWinner(squares) {
+function calculate_winner(squares) {
   const lines = [
     [0, 1, 2],
     [3, 4, 5],