TableOfMoves.js 1014 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. const React = require('react/addons');
  3. const GameStore = require('../stores/GameStore');
  4. const onGameChange = require('../mixins/onGameChange');
  5. const TableOfMoves = React.createClass({
  6. mixins: [React.addons.PureRenderMixin, onGameChange],
  7. getInitialState() {
  8. return {
  9. moves: GameStore.getMoves()
  10. };
  11. },
  12. render() {
  13. return (
  14. <table id="moves" className="clearfix">
  15. <thead>
  16. <tr>
  17. <th>Table of moves</th>
  18. </tr>
  19. </thead>
  20. <tbody>
  21. {this.state.moves.map((row, i) => (
  22. <tr key={i}>
  23. {row.map((move, j) => (
  24. <td key={j}>
  25. <strong>{i + 1}</strong>
  26. <span>{`. ${move}`}</span>
  27. </td>
  28. )).toArray()}
  29. </tr>
  30. )).toArray()}
  31. </tbody>
  32. </table>
  33. );
  34. },
  35. _onGameChange() {
  36. this.setState({
  37. moves: GameStore.getMoves()
  38. });
  39. }
  40. });
  41. module.exports = TableOfMoves;