Last active
May 2, 2021 11:32
-
-
Save jyotendra/14f879193e91aeac1ff7d8b775943db7 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 { ajax } from 'rxjs/ajax'; | |
// action creators | |
const fetchUser = username => ({ type: FETCH_USER, payload: username }); | |
const fetchUserFulfilled = payload => ({ type: FETCH_USER_FULFILLED, payload }); | |
// epic | |
const fetchUserEpic = action$ => action$.pipe( | |
ofType(FETCH_USER), | |
mergeMap(action => | |
ajax.getJSON(`https://api.github.com/users/${action.payload}`).pipe( | |
map(response => fetchUserFulfilled(response)) | |
) | |
) | |
); | |
// later... | |
dispatch(fetchUser('torvalds')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment