intershop-pwa
intershop-pwa copied to clipboard
explore: what if the ICM API could fetch multiple products at once?
PR Type
[x] Other: Showcase
What Is the Current Behavior?
Feature request #764
What Is the New Behavior?
Solution if the API could actually fetch multiple products at once.
Does this PR Introduce a Breaking Change?
[ ] Yes [x] No
@shauke I think this would actually be a nice feature to have for the ICM API. It shouldn't be any API break either 😉
Waiting for ICM internal request to provide a multiple SKUs REST API call: https://dev.azure.com/intershop-com/Products/_workitems/edit/64436 https://dev.azure.com/intershop-com/Products/_workitems/edit/54822
2 years later, this is still an interesting feature. We're using this with a slightly modified effect in PWA 3.2.0 to reduce the mass execution of product calls when working with multiple product carousels:
loadProducts$ = createEffect(() =>
this.actions$.pipe(
ofType(loadProduct),
// accumulate all actions to windows
window(this.actions$.pipe(ofType(loadProduct), debounceTime(250))),
mergeMap(window$ =>
window$.pipe(
mapToPayloadProperty('sku'),
// take slices
bufferCount(50),
// filter out duplicates
map(skus => skus.filter((v, i, a) => a.indexOf(v) === i)),
filter(skus => !!skus.length),
// make call
mergeMap(skus =>
this.productsService.getProducts(skus)?.pipe(
concatMap(({ products }) => [...products.map(product => loadProductSuccess({ product }))]),
mapErrorToAction(loadProductsBySkusFail, { skus })
)
)
)
)
)
);