Guest User

Untitled

a guest
Dec 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import { Inject, Injectable, Optional } from '@angular/core';
  2. import { ActivatedRoute } from '@angular/router';
  3.  
  4. import { Actions, Effect, ofType } from '@ngrx/effects';
  5. import { SchedulerLike } from 'rxjs';
  6. import { async } from 'rxjs/internal/scheduler/async';
  7. import { delay, map } from 'rxjs/operators';
  8.  
  9. import { CreateTripInformationFromQuery } from '../actions';
  10. import { LoadTripOverview, PageLoadActionTypes } from '../actions/page-load.actions';
  11.  
  12. export const DELAY_TIME: number = 20;
  13.  
  14. @Injectable()
  15. export class TripInformationEffects {
  16. constructor(
  17. private actions$: Actions,
  18. private activatedRoute: ActivatedRoute,
  19. @Optional() @Inject(async) private scheduler: SchedulerLike,
  20. @Optional() @Inject(DELAY_TIME) private delayTime: number,
  21. ) {}
  22.  
  23. /**
  24. * @route :country/:language->trip
  25. * @listen [PageLoad] Load Trip Overview
  26. * @dispatch [TripInformation] Create form query
  27. */
  28. /* tslint:disable:member-ordering */
  29. @Effect()
  30. public loadTripOverview$ = this.actions$.pipe(
  31. ofType<LoadTripOverview>(PageLoadActionTypes.LoadTripOverview),
  32. map(() => new CreateTripInformationFromQuery(this.activatedRoute.snapshot.queryParams))
  33. );
  34.  
  35. @Effect()
  36. public loadTripOverviewDelay$ = this.actions$.pipe(
  37. ofType<LoadTripOverview>(PageLoadActionTypes.LoadTripOverview),
  38. delay(this.delayTime, this.scheduler),
  39. map(() => new CreateTripInformationFromQuery(this.activatedRoute.snapshot.queryParams))
  40. );
  41. }
Add Comment
Please, Sign In to add comment