Skip to content

Instantly share code, notes, and snippets.

@MikeRyanDev
Last active November 2, 2017 19:43
Show Gist options
  • Save MikeRyanDev/4e6a0ab3b3b9e7d81d0ccfb31e2ee3a3 to your computer and use it in GitHub Desktop.
Save MikeRyanDev/4e6a0ab3b3b9e7d81d0ccfb31e2ee3a3 to your computer and use it in GitHub Desktop.
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