TableOfMoves.js 1021 B

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