Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 20x 20x 20x 20x 20x 20x 20x 48x 48x 48x 3x 2x | import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { distinct, map, mergeMap } from 'rxjs/operators';
import { PromotionsService } from 'ish-core/services/promotions/promotions.service';
import { mapErrorToAction, mapToPayloadProperty } from 'ish-core/utils/operators';
import { loadPromotion, loadPromotionFail, loadPromotionSuccess } from './promotions.actions';
@Injectable()
export class PromotionsEffects {
constructor(private actions$: Actions, private promotionsService: PromotionsService) {}
loadPromotion$ = createEffect(() =>
this.actions$.pipe(
ofType(loadPromotion),
mapToPayloadProperty('promoId'),
// trigger the promotion REST call only once for each distinct promotion id (per application session)
distinct(),
mergeMap(
promoId =>
this.promotionsService.getPromotion(promoId).pipe(
map(promotion => loadPromotionSuccess({ promotion })),
mapErrorToAction(loadPromotionFail, { promoId })
),
5
)
)
);
}
|