Rename stepNumber to step_number
authorCarl Worth <cworth@cworth.org>
Thu, 4 Jun 2020 23:19:11 +0000 (16:19 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 4 Jun 2020 23:19:11 +0000 (16:19 -0700)
And drop the dead-code jumpTo while we're at it.

I'm gradually rewriting the original tutorial code into my own style.

tictactoe/tictactoe.jsx

index 42c32ef29041345a03d2ca2ddb7ae5cbea5fd2c2..d462ae14f164f34b74037d4820f919beaa60d3f1 100644 (file)
@@ -118,7 +118,7 @@ class Game extends React.Component {
           squares: Array(9).fill(null)
         }
       ],
-      stepNumber: 0,
+      step_number: 0,
       next_to_play: Team.X
     };
   }
@@ -134,13 +134,13 @@ class Game extends React.Component {
           squares: Array(9).fill(null)
         }
       ],
-      stepNumber: 0,
+      step_number: 0,
       next_to_play: Team.X
     });
   }
 
   receiveMove(i) {
-    const history = this.state.history.slice(0, this.state.stepNumber + 1);
+    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]) {
@@ -158,7 +158,7 @@ class Game extends React.Component {
           squares: squares
         }
       ]),
-      stepNumber: history.length,
+      step_number: history.length,
       next_to_play: next_to_play
     });
   }
@@ -174,16 +174,9 @@ class Game extends React.Component {
     }
   }
 
-  jumpTo(step) {
-    this.setState({
-      stepNumber: step,
-      next_to_play: (step % 2) === 0
-    });
-  }
-
   render() {
     const history = this.state.history;
-    const current = history[this.state.stepNumber];
+    const current = history[this.state.step_number];
     const winner = calculateWinner(current.squares);
 
     let status;