Select Git revision
Forked from
Vincent MAZENOD / blog.limos.fr
Source project has a limited visibility.
bar.effects.ts 806 B
import { Actions, createEffect, ofType } from "@ngrx/effects";
import { Injectable } from "@angular/core";
import { catchError, map, mergeMap } from "rxjs/operators";
import { EMPTY, of } from "rxjs";
import { BarActionsTypes, FetchBarsFailed, FetchBarsSuccess } from "../actions/bar.actions";
import { BarService } from "../../services/bar.service";
import { Bar } from "../../models/bar.model";
@Injectable()
export class BarEffects {
constructor(
private actions$: Actions,
private barService: BarService
) {}
loadBars$ = createEffect(() => this.actions$.pipe(
ofType(BarActionsTypes.FETCH_BARS),
mergeMap(() => this.barService.getAll()
.pipe(
map((bars: Bar[]) => (new FetchBarsSuccess(bars))),
catchError(() => of(new FetchBarsFailed('failed fetching all bars')))
))
));
}