-
-
Save amowu/0180e039e0a839557b4ee54b71cf71e3 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 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