-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lesson 18 #11
base: master
Are you sure you want to change the base?
Lesson 18 #11
Conversation
<Route path="/rules" component={Rules}></Route> | ||
<Route path="/game" component={GameOfLife}></Route> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а почему тут появились закрывающие теги? зачем?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Странно, сейчас уберу, сами добавились автоматом.
constructor(props: Timer) { | ||
super(props); | ||
this.timerId = props.timerID as NodeJS.Timeout; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зачем тебе конструктор? у тебя уже подклчюен плагин для class-properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Только разобрался с этим, понял, что не нужно было так делать.
this.timerId = props.timerID as NodeJS.Timeout; | ||
} | ||
onClick = (x: number, y: number) => { | ||
this.props['setFill']({ x, y }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему скобочная нотация? точечная же короче
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Взял из примера, а потом когда разобрался, забыл исправить.
if (isRunningGame || gameStarted) { | ||
this.timerId = setInterval(() => { | ||
this.props.isGame(); | ||
}, speed); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
надеюсь, таймер мы обсудили?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, можно просто его определять, и использовать внутри компонента.
export function setFill(payload: Coordinates) { | ||
return { | ||
type: SET_CELL, | ||
payload, | ||
}; | ||
} | ||
|
||
export function clearBoard() { | ||
return { | ||
type: CLEAR_BOARD, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
как на счет redux-toolkit?
ну или хотя бы свой хелпер сделать, это же просто куча однотипных действий
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я пробовал предварительно без 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
хорошо бы это все вынести в отдельную функцию и покрыть ее тестами
метод должен помещаться на экран - те не больше 25-35 строк
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Согласен, сделаю.
ccd0e60
to
2eba2a1
Compare
0135b35
to
845a24b
Compare
No description provided.