-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: дз 7. hard. реализация пайпа filter #101
base: lecture-7
Are you sure you want to change the base?
Conversation
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.
Привет!
Все классно 👍, оставил пару вопросов, посмотри, пожалуйста
@@ -37,7 +12,7 @@ | |||
> | |||
<div class="cards"> | |||
<app-card | |||
*ngFor="let product of productsGroup; trackBy: trackById" |
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.
Почему убрал trackBy
?
transform<T extends IProduct, K extends keyof T>(value: T[], name: K, propValue: T[K]): T[] { | ||
return value.filter((item: T) => { | ||
if (Object.hasOwn(item, name)) { | ||
if (typeof propValue === 'string') { |
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 class FilterPipe implements PipeTransform { | ||
transform<T extends IProduct, K extends keyof T>(value: T[], name: K, propValue: T[K]): T[] { | ||
return value.filter((item: T) => { | ||
if (Object.hasOwn(item, name)) { |
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.
А нужна ли тут проверка, типизация не спасает?
return value.filter((item: T) => { | ||
if (Object.hasOwn(item, name)) { | ||
if (typeof propValue === 'string') { | ||
const regExp = new RegExp(propValue); |
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.
Есть ли необходимость в отдельной регуляре? Почему бы не использовать includes
?
И оптимально ли для каждого цикла создавать одну и ту же регулярку?
No description provided.