Skip to content

Instantly share code, notes, and snippets.

@skoch-fixeads
Created November 18, 2016 18:19
Show Gist options
  • Save skoch-fixeads/688b310b75f179cc57ed717d571252b0 to your computer and use it in GitHub Desktop.
Save skoch-fixeads/688b310b75f179cc57ed717d571252b0 to your computer and use it in GitHub Desktop.
RxJs multiple actions
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