arrow.js 536 B

12345678910111213141516
  1. export default function searchUsers(action$) {
  2. return action$.ofType(ActionTypes.SEARCHED_USERS)
  3. .map(action => action.payload.query)
  4. .filter(q => !!q)
  5. .switchMap(q =>
  6. Observable.timer(800) // debounce
  7. .takeUntil(action$.ofType(ActionTypes.CLEARED_SEARCH_RESULTS))
  8. .mergeMap(() => Observable.merge(
  9. Observable.of(replace(`?q=${q}`)),
  10. ajax.getJSON(`https://api.github.com/search/users?q=${q}`)
  11. .map(res => res.items)
  12. .map(receiveUsers)
  13. ))
  14. );
  15. };