Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active August 3, 2017 08:41
Show Gist options
  • Save cartant/b99bdb7f41b6b9b9c936ae3c8327e588 to your computer and use it in GitHub Desktop.
Save cartant/b99bdb7f41b6b9b9c936ae3c8327e588 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