Skip to content

Instantly share code, notes, and snippets.

@panvourtsis
Created March 8, 2019 19:48
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 panvourtsis/6e88eb157d42494951b0d51fecadab77 to your computer and use it in GitHub Desktop.
Save panvourtsis/6e88eb157d42494951b0d51fecadab77 to your computer and use it in GitHub Desktop.
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