Skip to content

ДЗ по лекции #11 #117

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

Open
wants to merge 3 commits into
base: lecture-11
Choose a base branch
from

Conversation

danterep
Copy link

@danterep danterep commented Dec 9, 2023

No description provided.

Copy link
Owner

@Letto228 Letto228 left a comment

Choose a reason for hiding this comment

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

Привет!
В целом все гуд, но есть пару вопросов/рекомендаций. Посмотри пожалуйста, буду ждать от тебя фидбека!)

priceRange: {
min: number;
max: number;
name?: string;
Copy link
Owner

Choose a reason for hiding this comment

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

Немного духоты по семантике от Егора: судя по коду - поля не опциональные - они будут иметь либо указанное в них значение, либо undefinde, но они точно будут определены в объекте. По этому корректней указать name: string | undefined, если я все правильно понял

Copy link
Author

@danterep danterep Dec 14, 2023

Choose a reason for hiding this comment

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

Привет! Не смог разобраться, почему поля не могут быть опциальными. Ведь если юзер вручную отредактирует URL в браузере с параметрами и удалит часть параметров или например перейдет на путь /products-list без параметров, то объект filter в FilterComponent не будет иметь какое-то поле или будет вообще пустым.

}

updateFilterForm() {
this.updateBrandsControl();
Copy link
Owner

Choose a reason for hiding this comment

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

Кажется, что в каком то кейсе мы будем вызывать updateBrandsControl за один ngOnChanges несколько раз, лучше в таком случае немного поменять условие в ngOnChnges:

    ngOnChanges({brands, filter}: SimpleChanges) {
        if (brands || filter) {
            this.updateBrandsControl();
        }

А в updateFilterForm updateBrandsControl не вызывать

Кстати, а почему метод решил сделать публичным?

Copy link
Author

Choose a reason for hiding this comment

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

Спасибо! Понял, что ошибся в логике. Исправил. Метод сделал публичным не специально, забыл указать private.

Comment on lines 78 to 80
map(filterFormValues => {
return this.processFilterFormValues(filterFormValues);
}),
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
map(filterFormValues => {
return this.processFilterFormValues(filterFormValues);
}),
map(filterFormValues => this.processFilterFormValues(filterFormValues)),

Copy link
Author

Choose a reason for hiding this comment

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

Спасибо! Поправил

Comment on lines 91 to 96
const productsFilter = {
...filterFormValues,
brands: sanitizedBrands,
} as IProductsFilter;

return productsFilter;
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
const productsFilter = {
...filterFormValues,
brands: sanitizedBrands,
} as IProductsFilter;
return productsFilter;
return productsFilter = {
...filterFormValues,
brands: sanitizedBrands,
} as IProductsFilter;

Copy link
Author

Choose a reason for hiding this comment

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

Здесь тоже исправил)

trackById(_index: number, {_id}: IProduct) {
return _id;
}

listenQueryParamsChange() {
this.activatedRoute.queryParams.subscribe(params => {
Copy link
Owner

Choose a reason for hiding this comment

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

Почему метод публичный? И почему не захотел использовать AsyncPipe?)

Copy link
Author

Choose a reason for hiding this comment

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

По AsyncPipe у меня как-то отложилось в голове, что | async лучше использовать для вывода каких-то данных в компоненте, а не для передачи между компонентами, т.е. я в принципе, изначально и не рассматривал такой вариант. Переделал. Думаю, лучше с async. Правда теперь у меня сомнения, не слишком ли громоздким получается шаблон компонента из-за дополнительного ng-container'а.

Публичным метод сделал опять же не специально, забыл. Исправил.


updateProductsFilter(productsFilter: IProductsFilter) {
this.router.navigate([''], {
relativeTo: this.activatedRoute,
Copy link
Owner

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