Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
perf(pagination): Loops in the pagination are now trackedBy.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomheller committed Apr 21, 2021
1 parent 9dbf1a2 commit a312ea2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 7 additions & 2 deletions libs/barista-components/pagination/src/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
</button>
</li>

<ng-container *ngFor="let block of _pages; let i = index">
<ng-container
*ngFor="let block of _pages; let i = index; trackBy: _blockTrackBy"
>
<li *ngIf="i > 0" class="dt-pagination-item">
<span [attr.aria-label]="_ariaLabelEllipsis"></span>
</li>

<li *ngFor="let page of block" class="dt-pagination-item">
<li
*ngFor="let page of block; trackBy: _pageTrackBy"
class="dt-pagination-item"
>
<button
*ngIf="page !== currentPage"
dt-button
Expand Down
16 changes: 16 additions & 0 deletions libs/barista-components/pagination/src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,22 @@ export class DtPagination implements OnInit {
}
}

/**
* @internal
* Track by function for the outer part of the _pages array loop
*/
_blockTrackBy(_index: number, block: number[]): number {
return block.reduce((sum, pageNumber) => sum + pageNumber, 0);
}

/**
* @internal
* Track by function for the inner part of the _pages array loop
*/
_pageTrackBy(_index: number, page: number): number {
return page;
}

/**
* @internal
* sets the current page and emits the changed event with the current page
Expand Down

0 comments on commit a312ea2

Please sign in to comment.