Skip to content

Commit

Permalink
perf: deactivate throttle time in products effects on SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi committed Mar 16, 2020
1 parent 7e35007 commit 274ca49
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/app/core/store/shopping/products/products.effects.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Injectable } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Dictionary } from '@ngrx/entity';
import { Store, select } from '@ngrx/store';
import { mapToParam, ofRoute } from 'ngrx-router';
import { identity } from 'rxjs';
import {
concatMap,
distinct,
Expand Down Expand Up @@ -49,7 +51,8 @@ export class ProductsEffects {
private store: Store<{}>,
private productsService: ProductsService,
private httpStatusCodeService: HttpStatusCodeService,
private productListingMapper: ProductListingMapper
private productListingMapper: ProductListingMapper,
@Inject(PLATFORM_ID) private platformId: string
) {}

@Effect()
Expand All @@ -73,7 +76,7 @@ export class ProductsEffects {
groupBy(([{ sku }]) => sku),
mergeMap(group$ =>
group$.pipe(
throttleTime(3000),
this.throttleOnBrowser(),
map(([{ sku }]) => new productsActions.LoadProduct({ sku }))
)
)
Expand Down Expand Up @@ -159,7 +162,7 @@ export class ProductsEffects {
groupBy(([product]) => product.productMasterSKU),
mergeMap(groups =>
groups.pipe(
throttleTime(3000),
this.throttleOnBrowser(),
map(
([product]) =>
new productsActions.LoadProductIfNotLoaded({
Expand Down Expand Up @@ -188,7 +191,7 @@ export class ProductsEffects {
groupBy(([product]) => product.sku),
mergeMap(groups =>
groups.pipe(
throttleTime(3000),
this.throttleOnBrowser(),
map(([product]) => new productsActions.LoadProductVariations({ sku: product.sku }))
)
)
Expand Down Expand Up @@ -313,4 +316,6 @@ export class ProductsEffects {
),
mergeMap(ids => ids.map(categoryId => new LoadCategory({ categoryId })))
);

private throttleOnBrowser = () => (isPlatformBrowser(this.platformId) ? throttleTime(3000) : map(identity));
}

0 comments on commit 274ca49

Please sign in to comment.