-
Notifications
You must be signed in to change notification settings - Fork 15
feat: реализовал пагинацию #86
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: lecture-6
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.
Привет!
В целом все гуд 👍
Есть пару комментариев по логике, и несколько вопросов, посмотри, пожалуйста. Буду очень ждать твоего фидбека!
<button mat-icon-button (click)="back()"> | ||
<mat-icon>chevron_left</mat-icon> | ||
</button> | ||
<button mat-button *ngFor="let pageIndex of pageIndexes; let index=index" ngClass="{{activeIndex == index ? 'active' : ''}}" (click)="go(index)"> |
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.
- Почему использовал
ngClass
, а не[class.active]=activeIndex == index
? - Почему решил использовать сравнение с приведением типов (
==
), а не строгое сравнение (===
)? - Почему решил использовать интерполяцию?
@@ -0,0 +1,8 @@ | |||
export interface IPaginationContext<T> { |
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.
Я бы добавил еще appPaginationOf
для того, чтобы передавать значение инпута в контексте. Поддержим функциональность используемую в стандартных структурных директивах)
selector: '[appPagination]' | ||
}) | ||
export class PaginationDirective<T> implements OnChanges, OnInit{ | ||
@Input() appPaginationOf!: T[] |
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.
Почему решил использовать !:
? Почему не стар расширять интерфейс до | null | undefined
, чтобы выходные данные были погибче и можно было работать без обертки в виде ngIf
?
} | ||
|
||
ngOnInit() { | ||
this.pageCount = this.appPaginationOf ? Math.ceil(this.appPaginationOf?.length/this.appPaginationChankSize) : 0; |
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.
Значение собирается из входных данных. Согласен, что они могут измениться? Может стоит реагируя на входные данные - обновлять значение на основе которых собирается контекст?
А нужен ли в this.appPaginationOf?.length
optional chaining ?.
?
} | ||
|
||
private getCurrentContext(currentPageIndex: number): IPaginationContext<T[]> { | ||
const startPosition:number = this.appPaginationChankSize*currentPageIndex || 0; |
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.
Почему тут поставил явную типзацию, а ниже нет?
Мне видится, что типизация нигдене нужна, т.к. наследование типов для констант в данном случае работает отлично
private getCurrentContext(currentPageIndex: number): IPaginationContext<T[]> { | ||
const startPosition:number = this.appPaginationChankSize*currentPageIndex || 0; | ||
const chankSize = this.appPaginationChankSize || 0; | ||
const chankCards= this.appPaginationOf?.slice(startPosition, startPosition + chankSize); |
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.
Вроде appPaginationOf
указан как !: T[]
, зачем нам тогда тут ?.
?
|
||
private next() { | ||
if(this.currentPageIndex$.value + 1 < this.pageCount){ | ||
const nextIndex = this.currentPageIndex$.value + 1; |
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.
Несколько раз вычисляется this.currentPageIndex$.value + 1
может стоит константу вынести до if
?
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.
В back
аналогично
private next() { | ||
if(this.currentPageIndex$.value + 1 < this.pageCount){ | ||
const nextIndex = this.currentPageIndex$.value + 1; | ||
const newIndex = nextIndex < this.appPaginationOf!.length ? nextIndex : 0; |
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.
nextIndex < this.appPaginationOf!.length
- а валидна ли теперь данная проверка? Кажется, для данной реализации функциональность зацикливания совсем ни к чему и ее можно убрать
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.
В back
аалогично
|
||
if (shouldShowItems) { | ||
this.currentPageIndex$.next(0); | ||
} |
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
не стоит ли тут добавить? Не будет ли бага при изменении входного массива, что увидим пустую страницу?
No description provided.