Skip to content

Commit

Permalink
Move debounce defintion to the top
Browse files Browse the repository at this point in the history
Try as workaround for #84
  • Loading branch information
afcapel committed Jan 16, 2022
1 parent 8f72b67 commit 9389eeb
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { Controller } from "@hotwired/stimulus"
const optionSelector = "[role='option']:not([aria-disabled])"
const activeSelector = "[aria-selected='true']"

const debounce = (fn, delay = 10) => {
let timeoutId = null

return (...args) => {
clearTimeout(timeoutId)
timeoutId = setTimeout(fn, delay)
}
}

export default class Autocomplete extends Controller {
static targets = ["input", "hidden", "results"]
static classes = ["selected"]
Expand Down Expand Up @@ -282,13 +291,4 @@ export default class Autocomplete extends Controller {
}
}

const debounce = (fn, delay = 10) => {
let timeoutId = null

return (...args) => {
clearTimeout(timeoutId)
timeoutId = setTimeout(fn, delay)
}
}

export { Autocomplete }

0 comments on commit 9389eeb

Please sign in to comment.