Skip to content

Instantly share code, notes, and snippets.

@jyotendra
Last active May 2, 2021 11:32
Show Gist options
  • Save jyotendra/14f879193e91aeac1ff7d8b775943db7 to your computer and use it in GitHub Desktop.
Save jyotendra/14f879193e91aeac1ff7d8b775943db7 to your computer and use it in GitHub Desktop.
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