Skip to content

Instantly share code, notes, and snippets.

@jtomaszewski
Last active July 9, 2019 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtomaszewski/8e8ad1f4367fcb05992b48c24c95047d to your computer and use it in GitHub Desktop.
Save jtomaszewski/8e8ad1f4367fcb05992b48c24c95047d to your computer and use it in GitHub Desktop.
// 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