Skip to content

Instantly share code, notes, and snippets.

@amowu
Forked from f0rr0/localitySuggest.js
Created October 9, 2017 14:44
Show Gist options
  • Save amowu/0180e039e0a839557b4ee54b71cf71e3 to your computer and use it in GitHub Desktop.
Save amowu/0180e039e0a839557b4ee54b71cf71e3 to your computer and use it in GitHub Desktop.
export default function localitySelect(action$, store, { ajax }) {
return action$
.ofType('LOCALITY_AUTOCOMPLETE')
.debounceTime(150)
.distinctUntilChanged()
.switchMap(({ payload: { text, cursor } }) => {
return ajax
.getJSON(
`${api.searchSuggest}&cursor=${cursor}&string=${text}`
)
.retry(3)
.map(({ response }) => ({
type: 'LOCALITY_SUGGEST',
payload: { data: response }
}))
.catch(error =>
Observable.of({
type: 'LOCALITY_SUGGEST',
payload: { error },
error: true
})
)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment