Skip to content

Instantly share code, notes, and snippets.

@malakhov-dmitrii
Last active March 20, 2019 11:29
Show Gist options
  • Save malakhov-dmitrii/e6688be641bbe5834e2c2afefa716d66 to your computer and use it in GitHub Desktop.
Save malakhov-dmitrii/e6688be641bbe5834e2c2afefa716d66 to your computer and use it in GitHub Desktop.
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