Last active
March 20, 2019 11:29
-
-
Save malakhov-dmitrii/e6688be641bbe5834e2c2afefa716d66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { Actions, Effect, ofType } from '@ngrx/effects'; | |
import { EMPTY } from 'rxjs'; | |
import { map, mergeMap } from 'rxjs/operators'; | |
@Injectable() | |
export class MovieEffects { | |
@Effect() | |
loadMovies$ = this.actions$ | |
.pipe( | |
// Определяем тип события | |
ofType('[Login Page] Login'), | |
// Выполняем запрос к серверу | |
mergeMap((action) => this.authService.login(action.payload) | |
.pipe( | |
// Получаем ответ и отправляем новое событие | |
map(movies => ({ type: '[Login Page] Login Success', payload: posts })), | |
catchError(() => EMPTY) | |
)) | |
) | |
); | |
constructor( | |
private actions$: Actions, | |
private moviesService: MoviesService | |
) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment