Skip to content

заготовки для урока по ФП#24

Merged
saitonakamura merged 4 commits into
nickovchinnikov:masterfrom
saitonakamura:lesson-13-examples
May 31, 2020
Merged

заготовки для урока по ФП#24
saitonakamura merged 4 commits into
nickovchinnikov:masterfrom
saitonakamura:lesson-13-examples

Conversation

@saitonakamura
Copy link
Copy Markdown
Contributor

No description provided.

return new Error(`${key} is required`);
};

// export class Validator {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Точно нужны такие большие закомментированные куски?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Да, там кроется логика для второй валидации которую они делают самостоятельно

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

поставь тогда пометку плиз, чтобы не забыть зачем, будет удобно

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

сделал

Comment thread src/lesson13/validator.ts Outdated
Comment thread src/lesson13/validator.ts
return !isValid;
}

checkIsNotEmpty(key: string) {
Copy link
Copy Markdown
Owner

@nickovchinnikov nickovchinnikov May 21, 2020

Choose a reason for hiding this comment

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

Потенциальный баг Boolean(0) === false
Все таки стоит сделать более явно, можно с помощью ramda

   import { is, isNil, isEmpty } from 'ramda'
   //...
    const value = this.values[key];
    if (is(Boolean, value)) {
       this.errors[key] = undefined
       return
    }
    if (isEmpty(value) || isNil(value)) {
       this.errors[key] = new Error(`${key} is required`);
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ну как вот эта проверка это и делает typeof value !== "number" && typeof value !== "boolean"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Boolean(0) === false явно не обрабатывается
ну и мне пришлось потратить много времени, чтобы понять все кейсы обрабатываемые этой строчкой и додебажить в голове до бага. Являюсь сторонником явных подходов, они и читаются лучше и ошибиться сложнее

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

В том числе я за явные преобразования типов, !!string и прочее очень смущают

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

переписал на явный switch

Comment thread src/lesson13/validator.ts Outdated
Comment thread src/screens/FormScreen.tsx
Copy link
Copy Markdown
Owner

@nickovchinnikov nickovchinnikov left a comment

Choose a reason for hiding this comment

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

Прошу обратить внимание на комменты

@saitonakamura saitonakamura merged commit 69d37b0 into nickovchinnikov:master May 31, 2020
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