Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active August 3, 2017 08:41
Show Gist options
  • Save cartant/5e6a77d2f1d287be3b5eeb5a7a364894 to your computer and use it in GitHub Desktop.
Save cartant/5e6a77d2f1d287be3b5eeb5a7a364894 to your computer and use it in GitHub Desktop.
import { Observable } from 'rxjs/Observable';
import { ajax } from 'rxjs/observable/dom/ajax';
const getRepos = action$ =>
action$.ofType('REPOS_REQUEST')
.map(action => action.payload.user)
.switchMap(user => ajax.getJSON(`https://api.notgithub.com/users/${user}/repos`))
.map(repos => { type: 'REPOS_RESPONSE', payload: { repos } })
.catch(error => Observable.of({ type: 'REPOS_ERROR' }))
.tag('getRepos');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment