File tree Expand file tree Collapse file tree 2 files changed +6
-14
lines changed Expand file tree Collapse file tree 2 files changed +6
-14
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ export function ReaderDepthTracker() {
5353 if ( document . documentElement . scrollHeight - window . innerHeight === 0 ) {
5454 return ( ) => { } ;
5555 }
56- const debouncedTrackProgress = debounce ( trackProgress , 20 ) ;
56+ const debouncedTrackProgress = debounce ( trackProgress , 50 ) ;
5757
5858 window . addEventListener ( 'scroll' , debouncedTrackProgress ) ;
5959 return ( ) => {
Original file line number Diff line number Diff line change @@ -115,18 +115,10 @@ export const stripTrailingSlash = (url: string) => {
115115 * @returns A debounced function.
116116 * @see https://davidwalsh.name/javascript-debounce-function
117117 */
118- export function debounce ( func : Function , wait = 20 , immediate = true ) {
119- let timeout : ReturnType < typeof setTimeout > | null ;
120- return function ( ) {
121- const context = this ;
122- const args = arguments ;
123- const later = function ( ) {
124- timeout = null ;
125- if ( ! immediate ) func . apply ( context , args ) ;
126- } ;
127- const callNow = immediate && ! timeout ;
128- if ( timeout ) clearTimeout ( timeout ) ;
129- timeout = setTimeout ( later , wait ) ;
130- if ( callNow ) func . apply ( context , args ) ;
118+ export function debounce < T extends unknown [ ] > ( func : ( ...args : T ) => void , delay : number ) {
119+ let timer : ReturnType < typeof setTimeout > ;
120+ return function ( ...args : T ) {
121+ clearTimeout ( timer ) ;
122+ timer = setTimeout ( ( ) => func . apply ( this , args ) , delay ) ;
131123 } ;
132124}
You can’t perform that action at this time.
0 commit comments