Skip to content

Instantly share code, notes, and snippets.

@daniele-zurico
Created June 19, 2018 18:13
Show Gist options
  • Save daniele-zurico/2ac60285a179abaeabf5dc01875d88e9 to your computer and use it in GitHub Desktop.
Save daniele-zurico/2ac60285a179abaeabf5dc01875d88e9 to your computer and use it in GitHub Desktop.
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