From 9389eebc4b179634115d7dc0bd0aaf6147401720 Mon Sep 17 00:00:00 2001 From: Alberto Fernandez-Capel Date: Sun, 16 Jan 2022 14:59:56 +0000 Subject: [PATCH] Move debounce defintion to the top Try as workaround for https://github.com/afcapel/stimulus-autocomplete/issues/84 --- src/autocomplete.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/autocomplete.js b/src/autocomplete.js index c23a425..b70ccab 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -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"] @@ -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 }