Last active
April 24, 2017 09:34
-
-
Save aaronmcadam/7fe0ddf8a1f40a0a7bae573a39158225 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
export function fetchReposByUser(sources) { | |
const user$ = sources.ACTION | |
.filter(action => action.type === ActionTypes.REQUESTED_USER_REPOS) | |
.map(action => action.payload.user); | |
const request$ = user$ | |
.map(user => ({ | |
url: `https://api.github.com/users/${user}/repos`, | |
category: 'users' | |
})); | |
const response$ = sources.HTTP | |
.select('users') | |
.flatten(); | |
const action$ = xs.combine(response$, user$) | |
.map(arr => actions.receiveUserRepos(arr[1], arr[0].body)); | |
return { | |
ACTION: action$, | |
HTTP: request$ | |
} | |
} |
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 xs from 'xstream'; | |
import { combineCycles } from 'redux-cycles'; | |
import * as actions from '../actions'; | |
import * as ActionTypes from '../ActionTypes'; | |
export function fetchApiStatus(sources) { | |
const request$ = sources.ACTION | |
.filter(action => action.type === ActionTypes.REQUESTED_API_STATUS) | |
.map(() => { | |
return { | |
category: 'status', | |
url: 'https://api.github.com/users/aaronmcadam', | |
accept: 'application/json', | |
type: 'application/json; charset=utf-8', | |
// progress: true, | |
// headers: { | |
// Authorization: 'Bearer 1234abcd', | |
// }, | |
// withCredentials: true, | |
} | |
}) | |
const action$ = sources.HTTP | |
.select('status') | |
.flatten() | |
.map((response) => actions.receiveApiStatus(response.body)) | |
return { | |
ACTION: action$, | |
HTTP: request$ | |
} | |
} | |
export default combineCycles(fetchApiStatus); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment