Skip to content

Commit

Permalink
perf: lazily fetch products for CMS carousels (#1581)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi authored Jan 29, 2024
1 parent 093f1ec commit cbe9072
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit cbe9072

Please sign in to comment.