Created
September 7, 2017 12:13
This file contains 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