File tree Expand file tree Collapse file tree 1 file changed +8
-29
lines changed Expand file tree Collapse file tree 1 file changed +8
-29
lines changed Original file line number Diff line number Diff line change @@ -23,33 +23,12 @@ export function dasherize(string) {
2323 } )
2424}
2525
26- export function debounce ( func , wait , immediate ) {
27- var timeout , result ;
28-
29- var later = function ( context , args ) {
30- timeout = null ;
31- if ( args ) result = func . apply ( context , args ) ;
32- } ;
33-
34- var debounced = function ( ...args ) {
35- if ( timeout ) clearTimeout ( timeout ) ;
36- if ( immediate ) {
37- var callNow = ! timeout ;
38- timeout = setTimeout ( later , wait ) ;
39- if ( callNow ) result = func . apply ( this , args ) ;
40- } else {
41- timeout = setTimeout ( function ( ) {
42- func ( ...args ) ;
43- } , wait ) ;
44- }
45-
46- return result ;
47- } ;
48-
49- debounced . cancel = function ( ) {
50- clearTimeout ( timeout ) ;
51- timeout = null ;
52- } ;
53-
54- return debounced ;
26+ export function debounce ( callback , wait ) {
27+ let timeoutId = null
28+ return ( ...args ) => {
29+ clearTimeout ( timeoutId )
30+ timeoutId = setTimeout ( ( ) => {
31+ callback . apply ( null , args )
32+ } , wait )
33+ }
5534}
You can’t perform that action at this time.
0 commit comments