Last active
September 6, 2017 01:08
-
-
Save Calvin-Huang/eee0a624c9f81d12bb09cb236c0f555a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 '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