-
Notifications
You must be signed in to change notification settings - Fork 10
Socks shop #14
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: master
Are you sure you want to change the base?
Socks shop #14
Conversation
export class ShopComponent implements OnInit{ | ||
totalItems = 100; | ||
pageSize = 8; | ||
currentPage = 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.
In een prod applicatie zou ik hier ook een apart component van maken
class Paginator {
@Output() pageChanged = new EventEmitter<PaginationInfo>();
}
Je wil paginatie toevoegen aan de SocksShop, maar later ook op de ReviewsPage en op de UsersPage en op de ...
Maar je wil de paginatie code niet elke keer gaan herhalen!
vb:
class PagedItemComponent {}
Dit is al iets ingewikkelder, je zal vb met een slot moeten werken: <ng-content></ng-content>
Grote voordeel:
Je ShopComponent begaat geen SRP violations: nu gaat de ShopComponent paginatie code bevatten, en later ook Filter code, en sorteer code etc...
En je kan het hergebruiken voor alles waardoor je bugfixes (off by 1 errors?) en changes (de paginatie buttons moeten anders gepositioneed & gestyled worden) maar op 1 plaats moet doen
socks$!: Observable<Sock[]>; | ||
socks: Sock[] = []; |
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.
Avoid fields in components.
Het is hier ook niet meer super duidelijk dat socks
enkel een bepaalde pagina van socks bevat.
Definieer meerdere Observables:
socks$!: Observable<Sock[]>;
totalCount$ = this.socks$.pipe(map(socks => socks.length))
pagedSocks = combineLatest([this.socks$, this.pagination$]).pipe(map(([socks, pagination]) => socks.slice(...));
this.socks$.pipe(last()) | ||
.subscribe(allSocks => { | ||
this.socks = this.getSocksPage(allSocks, this.currentPage, this.pageSize) | ||
}) |
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.
Omwille van de .subscribe
introduceer je namelijk subtiele fouten
Na een page change ga je hier opnieuw de http call uitvoeren.
Als er sindsdien een sock toegevoegd is, dan is de totalCount daarna incorrect!
No description provided.