All files / src/app/core/store/content/includes includes.effects.ts

100% Statements 15/15
100% Branches 0/0
100% Functions 4/4
100% Lines 14/14

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 32 33 34 3510x 10x 10x 10x   10x 10x   10x     10x   5x 5x     5x 5x         4x   8x                  
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { identity } from 'rxjs';
import { groupBy, map, mergeMap, switchMap } from 'rxjs/operators';
 
import { CMSService } from 'ish-core/services/cms/cms.service';
import { mapErrorToAction, mapToPayloadProperty } from 'ish-core/utils/operators';
 
import { loadContentInclude, loadContentIncludeFail, loadContentIncludeSuccess } from './includes.actions';
 
@Injectable()
export class IncludesEffects {
  constructor(
    private actions$: Actions,
    private cmsService: CMSService
  ) {}
 
  loadContentInclude$ = createEffect(() =>
    this.actions$.pipe(
      ofType(loadContentInclude),
      mapToPayloadProperty('includeId'),
      groupBy(identity),
      mergeMap(group$ =>
        group$.pipe(
          switchMap(includeId =>
            this.cmsService
              .getContentInclude(includeId)
              .pipe(map(loadContentIncludeSuccess), mapErrorToAction(loadContentIncludeFail))
          )
        )
      )
    )
  );
}