Skip to content

Instantly share code, notes, and snippets.

@amcdnl
Last active June 5, 2018 22:52
Show Gist options
  • Save amcdnl/d9302ff131196da14d804187d84458ee to your computer and use it in GitHub Desktop.
Save amcdnl/d9302ff131196da14d804187d84458ee to your computer and use it in GitHub Desktop.
import { Store, Action, ofType } from '@ngrx/store';
import { catchError } from 'rxjs/operators';
import { of } from 'rxjs/observable/of';
import { switchMap, map } from 'rxjs/operators';
export class EffectError implements Action {
readonly type = '[Error] Effect Error';
}
@Injectable()
export class PizzaEffects {
constructor(
private store: Store<any>,
private update$: Actions,
private pizzaService: PizzaService
) {}
@Effect()
loadPizza$ = this.update$.pipe(
ofType('LOAD_PIZZA'),
map((action: LoadPizza) => action.payload),
switchMap((pizzaId: string) =>
this.pizzaService.get(pizzaId).pipe(
map((pizza: Pizza) => new LoadPizzaSuccess(pizza)),
catchError(() => of(new EffectError()))
))
);
}
@michael-letcher
Copy link

import { Injectable } from '@angular/core';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { of } from 'rxjs';
import { catchError, switchMap } from 'rxjs/operators';

If this is for Angular6/rxjs6 the these are the missing/updated imports which is causing confusion in your article.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment