Created
November 18, 2016 18:19
-
-
Save skoch-fixeads/688b310b75f179cc57ed717d571252b0 to your computer and use it in GitHub Desktop.
RxJs multiple actions
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
action$.ofType(LOGIN_REQUEST) | |
.switchMap(() => | |
Observable.ajax.post( | |
'http://www.endpoint.com', | |
{ | |
username: 'user', | |
password: 'password' | |
}) | |
// Note the different operator here | |
.flatMap(payload => | |
// Concat 2 observables so they fire sequentially | |
Observable.concat( | |
Observable.of({ type: LOGIN_SUCCESS, payload: payload.response }), | |
Observable.of({ type: NOTIFY_SUCCESS, payload: payload.response }) | |
) | |
) | |
.takeUntil(action$.ofType(LOGIN_ABORT)) | |
.catch(({ xhr }) => Observable.of(loginFailed(xhr.response))) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment