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

perf: lazily fetch products for CMS carousels #1581

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<ng-container *ngIf="listStyle === 'carousel'; else plainList">
<div class="product-list">
<swiper [config]="swiperConfig">
<ng-template *ngFor="let sku of products" swiperSlide>
<ng-template *ngFor="let sku of products" swiperSlide let-data>
<div [ngClass]="listItemCSSClass">
<ish-product-item
*ngIf="lazyFetch(data.isVisible, sku)"
ishProductContext
[sku]="sku"
[configuration]="listItemConfiguration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export class ProductsListComponent implements OnChanges {

productSKUs$: Observable<string[]>;

/**
* track already fetched SKUs
*/
private fetchedSKUs = new Set<string>();

/**
* configuration of swiper carousel
* https://swiperjs.com/swiper-api
Expand All @@ -44,6 +49,7 @@ export class ProductsListComponent implements OnChanges {
private shoppingFacade: ShoppingFacade
) {
this.swiperConfig = {
watchSlidesProgress: true,
direction: 'horizontal',
navigation: true,
pagination: {
Expand All @@ -64,6 +70,13 @@ export class ProductsListComponent implements OnChanges {
);
}

lazyFetch(fetch: boolean, sku: string): boolean {
if (fetch) {
this.fetchedSKUs.add(sku);
}
return this.fetchedSKUs.has(sku);
}

/**
* Configure Swiper slidesPerView/slidesPerGroup settings
* with breakpoint responsive design considerations based on the given slide items.
Expand Down
Loading