Last active
June 5, 2018 22:52
-
-
Save amcdnl/d9302ff131196da14d804187d84458ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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())) | |
)) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If this is for Angular6/rxjs6 the these are the missing/updated imports which is causing confusion in your article.