Skip to content

Commit a0aab0e

Browse files
fix debounce
1 parent 7886c72 commit a0aab0e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class RemoteInputElement extends HTMLElement {
44
constructor() {
55
super()
66
const fetch = (e: Event) => fetchResults.bind(null, this, true, e)
7-
const state = {currentQuery: null, oninput: (e: Event) => debounce(fetch(e)), fetch, controller: null}
7+
const state = {currentQuery: null, oninput: debounce((e: Event) => fetch(e)), fetch, controller: null}
88
states.set(this, state)
99
}
1010

@@ -142,13 +142,13 @@ async function fetchWithNetworkEvents(el: Element, url: string, options: Request
142142
}
143143
}
144144

145-
function debounce(callback: () => void) {
145+
function debounce<T>(callback: (args: T) => void) {
146146
let timeout: ReturnType<typeof setTimeout>
147-
return function() {
147+
return function(args: T) {
148148
clearTimeout(timeout)
149149
timeout = setTimeout(() => {
150150
clearTimeout(timeout)
151-
callback()
151+
callback(args)
152152
}, 300)
153153
}
154154
}

0 commit comments

Comments
 (0)