-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson 4 react component JSX #2
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
base: master
Are you sure you want to change the base?
Conversation
| @@ -1,0 +1,2 @@ | |||
| import React from 'react'; | |||
| import { render } from 'react-dom'; | |||
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.
Этого не должно быть здесь, перекину в векту master, предпологалось как шаблон использовать
src/lesson4/Cell.tsx
Outdated
|
|
||
| export default Cell; | ||
|
|
||
| export function getCell(props: CellProps) { |
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.
Принял, сделаю инлайново
src/lesson4/Cell.stories.tsx
Outdated
| }; | ||
|
|
||
| export const nonFilled = () => [ | ||
| <Cell x={number('x', 1)} y={number('y', 23)} key="nonFilled" />, |
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.
а зачем тут key?
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.
Косячнул, уберу. Здесь не нужен.
src/lesson4/Field.stories.tsx
Outdated
| export const emptyCell = () => [ | ||
| <Field | ||
| field={object('field', [ | ||
| [ |
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.
хорошо бы Array.from({length: 5}).fill(false) или вроде того, а то читать не особо понятно - еще и шанс ошибиться в числе элементов выше
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.
Сделаю тогда вот так
Array.from<boolean[]>({ length: 10 }).fill( Array.from<boolean>({ length: 10 }).fill(false), );
f3c3028 to
436303d
Compare
a4514e2 to
4d55bac
Compare
| const cellGridFillRandom = ( | ||
| rows: number, | ||
| columns: number, | ||
| cellStatus = () => Math.random() < 0.3, |
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.
Вроде один раз же определил в этом компоненте? Или я недопонял вопроса(
src/lesson4/GameOfLifeProto.tsx
Outdated
| this.state = { | ||
| fieldState: cellGridFillRandom(this.props.rows, this.props.columns), | ||
| }; | ||
| this.onClick = this.onClick.bind(this); |
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.
Это который вот этот @babel/plugin-proposal-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.
И мне тогда получается можно использовать методы компонента через стрелочные функции, правильно понимаю?
|
|
||
| public onClick() { | ||
| this.setState(() => { | ||
| const cloneFieldState = cellGridFillRandom( |
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.
на сколько я вижу, здесь коллбэк не обязателен
| field={this.state.fieldState} | ||
| onClick={this.onClick} | ||
| /> | ||
| <button className="btn" onClick={() => this.onClick()}> |
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.
Я заготовку начал делать видимо для метода, который будет при клике возвращать координаты ячейки и видимо забыл убрать, я уберу эту привязку
4d55bac to
34f1b74
Compare
0135b35 to
845a24b
Compare
No description provided.