TableOfMoves.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. import React from 'react/addons';
  3. import GameStore from '../stores/GameStore';
  4. import onGameChange from '../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. <td>
  24. <strong>{`${i + 1}.`}</strong>
  25. </td>
  26. {row.map((move, j) => (
  27. <td key={j}>
  28. <span>{move}</span>
  29. </td>
  30. )).toArray()}
  31. </tr>
  32. )).toArray()}
  33. </tbody>
  34. </table>
  35. );
  36. },
  37. _onGameChange() {
  38. this.setState({
  39. moves: GameStore.getMoves()
  40. });
  41. }
  42. });
  43. export default TableOfMoves;