Last active
November 2, 2017 19:43
-
-
Save MikeRyanDev/4e6a0ab3b3b9e7d81d0ccfb31e2ee3a3 to your computer and use it in GitHub Desktop.
This file contains 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 { _throw } from 'rxjs/observable/throw'; | |
import { of } from 'rxjs/observable/of'; | |
import { Actions } from '@ngrx/effects'; | |
class MyEffects { | |
@Effect() doSomething$ = this.actions$ | |
.ofType('SOMETHING') | |
.mergeMap(action => { | |
return this.http.post('/endpoint') | |
.mergeMap(result => { | |
if (result.type === BAD) { | |
return _throw(result); | |
} | |
return of(result); | |
}); | |
}) | |
.map(() => { /* to a success action */ }) | |
.catch(error => { /* to an error action */ }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment