11class RemoteInputElement extends HTMLElement {
22 currentQuery : string | null
3- debounceInputChange : ( Event ) => void
4- boundFetchResults : ( Event ) => void
3+ debounceInputChange : ( event : Event ) => void
4+ boundFetchResults : ( event : Event ) => void
5+
6+ constructor ( ) {
7+ super ( )
8+ this . currentQuery = null
9+ this . debounceInputChange = debounce ( ( ) => fetchResults ( this ) )
10+ this . boundFetchResults = ( ) => fetchResults ( this )
11+ }
512
613 static get observedAttributes ( ) {
714 return [ 'src' ]
@@ -20,8 +27,6 @@ class RemoteInputElement extends HTMLElement {
2027 input . setAttribute ( 'autocomplete' , 'off' )
2128 input . setAttribute ( 'spellcheck' , 'false' )
2229
23- this . debounceInputChange = debounce ( ( ) => fetchResults ( this ) )
24- this . boundFetchResults = ( ) => fetchResults ( this )
2530 input . addEventListener ( 'focus' , this . boundFetchResults )
2631 input . addEventListener ( 'change' , this . boundFetchResults )
2732 input . addEventListener ( 'input' , this . debounceInputChange )
@@ -99,8 +104,8 @@ async function fetchResults(remoteInput: RemoteInputElement, checkCurrentQuery:
99104 remoteInput . dispatchEvent ( new CustomEvent ( 'loadend' ) )
100105}
101106
102- function debounce ( callback ) {
103- let timeout
107+ function debounce ( callback : ( ) => void ) {
108+ let timeout : number
104109 return function ( ) {
105110 clearTimeout ( timeout )
106111 timeout = setTimeout ( ( ) => {
0 commit comments