Skip to content

Instantly share code, notes, and snippets.

@Calvin-Huang
Last active September 6, 2017 01:08
Show Gist options
  • Select an option

  • Save Calvin-Huang/eee0a624c9f81d12bb09cb236c0f555a to your computer and use it in GitHub Desktop.

Select an option

Save Calvin-Huang/eee0a624c9f81d12bb09cb236c0f555a to your computer and use it in GitHub Desktop.
import 'rxjs';
import { combineEpics } from 'redux-observable';
// Use RxJS ajax
const fetchEpic = (action$) =>
action$.ofType('FETCH_REQUESTED')
.mergeMap(action => Observable.ajax.get(action.payload.url))
.map(data => ({ type: 'FETCH_SUCCEEDED', data }))
.catch(error => Observable.of({ type: 'FETCH_FAILED', error }));
// Or simply use fetch
// const fetchEpic = (action$) =>
// action$.ofType('FETCH_REQUESTED')
// .mergeMap(fetch(action.payload.url).then(response => response.json()));
// .map(data => { type: 'FETCH_SUCCEEDED', data })
// .catch(error => Observable.of({ type: 'FETCH_FAILED', error }));
+export default combineEpics(
+ fetchEpic,
+);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment