Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement