Skip to content

Instantly share code, notes, and snippets.

@f0rr0
Created September 7, 2017 12:13
Show Gist options
  • Save f0rr0/5b47f56eef545c26dc4e0329f4365923 to your computer and use it in GitHub Desktop.
Save f0rr0/5b47f56eef545c26dc4e0329f4365923 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