Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// When SUBMIT action happens:
// - emit VALIDATE action,
// - validate the form,
// - and when validating the form finishes with success:
// - emit SUBMIT_START action.
const validateOnSubmitEpic = (action$, state$) => {
return action$.ofType(SUBMIT).switchMap(() => {
const validate$ = Observable.of({ type: VALIDATE });
const onValidate$ = Observable.merge(
action$.ofType({ type: VALIDATE_SUCCESS }),
action$.ofType({ type: VALIDATE_FAILURE })
)
.first()
.filter(action => action.type === VALIDATE_SUCCESS)
.mapTo({ type: SUBMIT_START });
return Observable.merge(validate$, onValidate$);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment