Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Lesson 18 #11

wants to merge 6 commits into from

Conversation

mkremnev
Copy link
Owner

No description provided.

Comment on lines +19 to +20
<Route path="/rules" component={Rules}></Route>
<Route path="/game" component={GameOfLife}></Route>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а почему тут появились закрывающие теги? зачем?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Странно, сейчас уберу, сами добавились автоматом.

Comment on lines 53 to 56
constructor(props: Timer) {
super(props);
this.timerId = props.timerID as NodeJS.Timeout;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем тебе конструктор? у тебя уже подклчюен плагин для class-properties

Copy link
Owner Author

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 });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему скобочная нотация? точечная же короче

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Взял из примера, а потом когда разобрался, забыл исправить.

Comment on lines 74 to 68
if (isRunningGame || gameStarted) {
this.timerId = setInterval(() => {
this.props.isGame();
}, speed);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

надеюсь, таймер мы обсудили?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, можно просто его определять, и использовать внутри компонента.

Comment on lines +11 to +22
export function setFill(payload: Coordinates) {
return {
type: SET_CELL,
payload,
};
}

export function clearBoard() {
return {
type: CLEAR_BOARD,
};
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

как на счет redux-toolkit?

ну или хотя бы свой хелпер сделать, это же просто куча однотипных действий

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я пробовал предварительно без toolkit, чтобы разобратьтся в общем с Redux. Следующим шагом хотел уже с toolkit сделать.

Comment on lines +50 to +73
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]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

хорошо бы это все вынести в отдельную функцию и покрыть ее тестами

метод должен помещаться на экран - те не больше 25-35 строк

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Согласен, сделаю.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants