Skip to content
Snippets Groups Projects
Select Git revision
  • 81831ee8a6e62422b4cc060478521e27d3708419
  • master default
2 results

bar.effects.ts

Blame
  • 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')))
    			))
    	));
    }