Created
March 8, 2019 19:48
-
-
Save panvourtsis/6e88eb157d42494951b0d51fecadab77 to your computer and use it in GitHub Desktop.
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
import { from, of, concat } from 'rxjs'; | |
import { catchError, mergeMap, switchMap, takeUntil } from 'rxjs/operators'; | |
import { startSubmit, stopSubmit } from 'redux-form'; | |
const exampleEpic = action$ => | |
action$.pipe( | |
ofType(types.ACTION_REQUEST), | |
switchMap(({ payload, meta }) => // yes, meta! | |
concat( | |
of(startSubmit(meta.formName)), // Here we define that this specific form is submitting | |
from(api.get(payload.data)).pipe( | |
mergeMap(response => | |
of( | |
addDataAction(response), // action 1 | |
pushInfoSnackbar('created successfully'), // action 2 | |
stopSubmit(meta.formName) // action 3 | |
) | |
), | |
takeUntil(action$.ofType(types.PAGE_CHANGED)), | |
catchError(() => | |
of(pushWarningSnackbar('Failed to create shareable folder'), stopSubmit(meta.formName)); // failed action | |
) | |
) | |
) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment