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

feat: дз 7. hard. реализация пайпа filter #101

Open
wants to merge 1 commit into
base: lecture-7
Choose a base branch
from

Conversation

aleksUkolov
Copy link

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.

Привет!
Все классно 👍, оставил пару вопросов, посмотри, пожалуйста

@@ -37,7 +12,7 @@
>
<div class="cards">
<app-card
*ngFor="let product of productsGroup; trackBy: trackById"
Copy link
Owner

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') {
Copy link
Owner

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)) {
Copy link
Owner

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

Choose a reason for hiding this comment

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

Есть ли необходимость в отдельной регуляре? Почему бы не использовать includes?

И оптимально ли для каждого цикла создавать одну и ту же регулярку?

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