Created
June 19, 2018 18:13
-
-
Save daniele-zurico/2ac60285a179abaeabf5dc01875d88e9 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
export class HeroesEffects { | |
@Effect() | |
fetch$: Observable<HeroesActions> = this.actions$ | |
.ofType(HeroesActionTypes.FetchHeroes) | |
.pipe( | |
withLatestFrom(this.store), | |
switchMap(([action, state]) => | |
this.service.getHeroes(getCurrentPage(state)).pipe( | |
map(data => new FetchHeroesSuccess(data)), | |
catchError(err => of(new FetchHeroesError(err))) | |
) | |
) | |
); | |
@Effect() | |
paginate$: Observable<HeroesActions> = this.actions$ | |
.ofType(HeroesActionTypes.ChangePage) | |
.pipe(map(() => new FetchHeroes())); | |
constructor( | |
private actions$: Actions, | |
private store: Store<State>, | |
private service: SwapiService | |
) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment