Skip to content

Instantly share code, notes, and snippets.

@lmatteis
Created December 3, 2016 14:57
Show Gist options
  • Save lmatteis/7f0e7195c6b08770a005129da80d10e4 to your computer and use it in GitHub Desktop.
Save lmatteis/7f0e7195c6b08770a005129da80d10e4 to your computer and use it in GitHub Desktop.
function main(sources) {
const user$ = sources.ACTION
// .debug(action => console.log(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(args => console.log(arguments));
// .map(receiveUserRepos.bind(null, user))
const searchQuery$ = sources.ACTION
.filter(action => action.type === ActionTypes.SEARCHED_USERS)
.map(action => action.payload.query)
.filter(q => !!q)
.compose(debounce(800))
.endWhen(
sources.ACTION.filter(action =>
action.type === ActionTypes.CLEARED_SEARCH_RESULTS)
)
const searchQueryRequest$ = searchQuery$
.map(q => ({
url: `https://api.github.com/search/users?q=${q}`,
category: 'query'
}))
const searchQueryResponse$ = sources.HTTP
.select('query')
.flatten()
.map(res => res.items)
.debug(items => console.log(items))
// .map(receiveUsers)
return {
HTTP: xs.merge(request$, searchQueryRequest$),
ACTION: xs.merge(action$),
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment