Last active
February 14, 2017 16:06
-
-
Save bertrandg/6207c52d8d58d4ca6f2ed924131a65c9 to your computer and use it in GitHub Desktop.
ngrx/effects simple example
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
@Effect() actionX$ = this.updates$ | |
.ofType('ACTION_X') | |
.map(toPayload) | |
.switchMap(payload => this.api.callApiX(payload) | |
.map(data => ({type: 'ACTION_X_SUCCESS', payload: data})) | |
.catch(err => Observable.of({type: 'ACTION_X_FAIL', payload: err})) | |
); | |
@Effect() actionY$ = this.updates$ | |
.ofType('ACTION_Y') | |
.map(toPayload) | |
.switchMap(payload => this.api.callApiY(payload) | |
.map(data => ({type: 'ACTION_Y_SUCCESS', payload: data})) | |
.catch(err => Observable.of({type: 'ACTION_Y_FAIL', payload: err})) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment