Conversation
| <Route path="/rules" component={Rules}></Route> | ||
| <Route path="/game" component={GameOfLife}></Route> |
There was a problem hiding this comment.
а почему тут появились закрывающие теги? зачем?
There was a problem hiding this comment.
Странно, сейчас уберу, сами добавились автоматом.
| constructor(props: Timer) { | ||
| super(props); | ||
| this.timerId = props.timerID as NodeJS.Timeout; | ||
| } |
There was a problem hiding this comment.
зачем тебе конструктор? у тебя уже подклчюен плагин для class-properties
There was a problem hiding this comment.
Только разобрался с этим, понял, что не нужно было так делать.
| this.timerId = props.timerID as NodeJS.Timeout; | ||
| } | ||
| onClick = (x: number, y: number) => { | ||
| this.props['setFill']({ x, y }); |
There was a problem hiding this comment.
почему скобочная нотация? точечная же короче
There was a problem hiding this comment.
Взял из примера, а потом когда разобрался, забыл исправить.
| if (isRunningGame || gameStarted) { | ||
| this.timerId = setInterval(() => { | ||
| this.props.isGame(); | ||
| }, speed); | ||
| } |
There was a problem hiding this comment.
Да, можно просто его определять, и использовать внутри компонента.
| export function setFill(payload: Coordinates) { | ||
| return { | ||
| type: SET_CELL, | ||
| payload, | ||
| }; | ||
| } | ||
|
|
||
| export function clearBoard() { | ||
| return { | ||
| type: CLEAR_BOARD, | ||
| }; | ||
| } |
There was a problem hiding this comment.
как на счет redux-toolkit?
ну или хотя бы свой хелпер сделать, это же просто куча однотипных действий
There was a problem hiding this comment.
Я пробовал предварительно без toolkit, чтобы разобратьтся в общем с Redux. Следующим шагом хотел уже с toolkit сделать.
| const amountAliveNeighbors = (x: number, y: number) => { | ||
| const eightNeighbors = [ | ||
| [-1, -1], | ||
| [-1, 0], | ||
| [-1, 1], | ||
| [0, 1], | ||
| [1, 1], | ||
| [1, 0], | ||
| [1, -1], | ||
| [0, -1], | ||
| ]; | ||
|
|
||
| return eightNeighbors.reduce((aliveNeighbors, neighbor) => { | ||
| const xCell = x + neighbor[0]; | ||
| const yCell = y + neighbor[1]; | ||
| const endBoard = | ||
| xCell >= 0 && | ||
| xCell < 20 && | ||
| yCell >= 0 && | ||
| yCell < 20; | ||
| if ( | ||
| aliveNeighbors < 4 && | ||
| endBoard && | ||
| prevBoard[xCell][yCell] |
There was a problem hiding this comment.
хорошо бы это все вынести в отдельную функцию и покрыть ее тестами
метод должен помещаться на экран - те не больше 25-35 строк
ccd0e60 to
2eba2a1
Compare
0135b35 to
845a24b
Compare
No description provided.