Created
December 25, 2019 01:18
-
-
Save alexytiger/4747e5e371cab31e30d6b4695f7df25d to your computer and use it in GitHub Desktop.
e-book
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 { Injectable } from '@angular/core'; | |
| import { Actions, ofType, createEffect } from '@ngrx/effects'; | |
| import { tap, map } from 'rxjs/operators'; | |
| import { ErrorActions, SnackBarActions } from '../actions'; | |
| import { AppearanceColor, SnackBarInterface } from '../../models'; | |
| @Injectable() | |
| export class ErrorEffects { | |
| constructor(private readonly actions$: Actions) { | |
| } | |
| handleError$ = createEffect( | |
| () => | |
| this.actions$.pipe( | |
| ofType(ErrorActions.errorMessage), | |
| map(action => action.errorMsg), | |
| tap(errorMsg => console.error('Got error:', errorMsg)), | |
| map(errorMsg => { | |
| const msg: SnackBarInterface = { | |
| message: errorMsg, | |
| color: AppearanceColor.Error | |
| }; | |
| return SnackBarActions.open({payload: msg}); | |
| } ) | |
| ) | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment