@@ -15,12 +15,12 @@ const JSXParser = acorn.Parser.extend(jsx());
15
15
16
16
/**
17
17
* @method throttle
18
- * @param f A function to throttle
19
- * @param t A number of milliseconds to use as throttling interval
20
- * @returns A function that limits input function, `f `, from being called more than once every `t ` milliseconds
18
+ * @param callback A function to throttle
19
+ * @param ms A number of milliseconds to use as throttling interval
20
+ * @returns A function that limits input function, `callback `, from being called more than once every `ms ` milliseconds
21
21
*
22
22
*/
23
- export const throttle = ( f : Function , t : number ) : Function => {
23
+ export const throttle = ( callback : Function , ms : number ) : Function => {
24
24
// Initialize boolean flags for callback, throttledFunc
25
25
let isOnCooldown = false ;
26
26
let isCallQueued = false ;
@@ -42,7 +42,7 @@ export const throttle = (f: Function, t: number): Function => {
42
42
43
43
// CASE 3: If we are ready to "fire":
44
44
// Execute the function, f, immediately
45
- f ( ) ;
45
+ callback ( ) ;
46
46
// Initiate a new cooldown period and reset the "call queue"
47
47
isOnCooldown = true ;
48
48
isCallQueued = false ;
@@ -53,14 +53,14 @@ export const throttle = (f: Function, t: number): Function => {
53
53
if ( isCallQueued ) {
54
54
isCallQueued = false ;
55
55
isOnCooldown = true ; // not needed I think
56
- f ( ) ;
57
- setTimeout ( runAfterTimeout , t ) ;
56
+ callback ( ) ;
57
+ setTimeout ( runAfterTimeout , ms ) ;
58
58
return ;
59
59
}
60
60
isOnCooldown = false ;
61
61
} ;
62
62
63
- setTimeout ( runAfterTimeout , t ) ;
63
+ setTimeout ( runAfterTimeout , ms ) ;
64
64
} ;
65
65
66
66
return throttledFunc ;
0 commit comments