Skip to content

Commit

Permalink
feat(throttle): use throttle instead of debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink committed Jul 31, 2021
1 parent 2eb1130 commit 6fa549b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
19 changes: 11 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"dependencies": {
"@geocodeearth/core-js": "^0.0.7",
"downshift": "6.1.3",
"lodash.debounce": "^4.0.8",
"lodash.escape": "^4.0.1",
"lodash.template": "^4.5.0",
"lodash.throttle": "^4.1.1",
"lodash.unescape": "^4.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
Expand Down
9 changes: 7 additions & 2 deletions src/autocomplete/autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React, { useState, useMemo, useCallback, useRef, useEffect } from 'react'
import { useCombobox } from 'downshift'
import { createAutocomplete } from '@geocodeearth/core-js'
import debounce from 'lodash.debounce'
import throttle from 'lodash.throttle'
import css from './autocomplete.css'
import strings from '../strings'
import { LocationMarker, Loading, Search as SearchIcon } from '../icons'
import escape from '../escape'

const throttleOptions = {
leading: false,
trailing: true
}

const emptyResults = {
text: '',
features: []
Expand Down Expand Up @@ -60,7 +65,7 @@ export default ({
}, [autocomplete])

const debouncedSearch = useCallback(
debounce(search, debounceWait, { trailing: true }),
throttle(search, debounceWait, throttleOptions),
[search]
)

Expand Down

0 comments on commit 6fa549b

Please sign in to comment.