SHARE
TWEET

Untitled

a guest Jul 18th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Injectable } from '@angular/core';
  2. import { Actions, Effect, ofType } from '@ngrx/effects';
  3. import { Action } from '@ngrx/store';
  4. import { Observable } from 'rxjs';
  5. import { map, switchMap } from 'rxjs/operators';
  6. import { ClubsService } from '../clubs.service';
  7. import {
  8.   RequestClubsAction,
  9.   ClubsActionType,
  10.   RespondClubsAction
  11. } from './clubs.actions';
  12. import { ClubsState } from './clubs.state';
  13.  
  14. @Injectable()
  15. export class ClubsEffects {
  16.   @Effect()
  17.   requestClubs$: Observable<Action> = this.actions$.pipe(
  18.     ofType<RequestClubsAction>(ClubsActionType.REQUEST_CLUBS),
  19.     switchMap(action => {
  20.       return this.clubService.getClubs().pipe(
  21.         map((response: ClubsState[]) => {
  22.           return new RespondClubsAction({ clubs: response });
  23.         })
  24.       );
  25.     })
  26.   );
  27.  
  28.   constructor(
  29.     private readonly actions$: Actions,
  30.     private readonly clubService: ClubsService
  31.   ) {}
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top