@@ -24,9 +24,9 @@ export const throttle = (callback: Function, ms: number): Function => {
24
24
let isOnCooldown = false ;
25
25
let isCallQueued = false ;
26
26
27
- // Wrap the passed-in function, f, in a callback function that "throttles"
28
- // (puts a limit on) the number of calls that can be made to function, f
29
- // in a given period of time (ms), t
27
+ // Wrap the passed-in function callback in a callback function that "throttles"
28
+ // (puts a limit on) the number of calls that can be made to function
29
+ // in a given period of time (ms)
30
30
const throttledFunc = ( ) : any => {
31
31
// CASE 1: In cooldown mode and we already have a function waiting to be executed,
32
32
// so do nothing
@@ -40,7 +40,7 @@ export const throttle = (callback: Function, ms: number): Function => {
40
40
}
41
41
42
42
// CASE 3: If we are ready to "fire":
43
- // Execute the function, f, immediately
43
+ // Execute the function callback immediately
44
44
callback ( ) ;
45
45
// Initiate a new cooldown period and reset the "call queue"
46
46
isOnCooldown = true ;
@@ -51,7 +51,7 @@ export const throttle = (callback: Function, ms: number): Function => {
51
51
const runAfterTimeout = ( ) : any => {
52
52
if ( isCallQueued ) {
53
53
isCallQueued = false ;
54
- isOnCooldown = true ; // not needed I think
54
+ isOnCooldown = true ;
55
55
callback ( ) ;
56
56
setTimeout ( runAfterTimeout , ms ) ;
57
57
return ;
@@ -68,7 +68,7 @@ export const throttle = (callback: Function, ms: number): Function => {
68
68
// Helper function to grab the getters/setters from `elementType`
69
69
/**
70
70
* @method getHooksNames
71
- * @param elementType The fiber `type`, A stringified function of the component the Fiber whose hooks we want corresponds to
71
+ * @param elementType The fiber `type`, A stringified function of the component, the Fiber whose hooks we want corresponds to
72
72
* @returns An array of strings
73
73
*/
74
74
export const getHooksNames = ( elementType : string ) : Array < string > => {
@@ -95,11 +95,11 @@ export const getHooksNames = (elementType: string): Array<string> => {
95
95
* Iterate through AST of every function declaration
96
96
* Check within each function declaration if there are hook declarations */
97
97
ast . forEach ( functionDec => {
98
- let body : any ;
99
- if ( functionDec . expression && functionDec . expression . body ) body = functionDec . expression . body . body ;
100
- else body = functionDec . body ? functionDec . body . body : [ ] ;
98
+ let declarationBody : any ;
99
+ if ( functionDec . expression && functionDec . expression . body ) declarationBody = functionDec . expression . body . body ; // check if functionDec.expression.body exists, then set declarationBody to functionDec's body
100
+ else declarationBody = functionDec . body ? functionDec . body . body : [ ] ;
101
101
// Traverse through the function's funcDecs and Expression Statements
102
- body . forEach ( ( elem : any ) => {
102
+ declarationBody . forEach ( ( elem : any ) => {
103
103
// Hooks will always be contained in a variable declaration
104
104
if ( elem . type === 'VariableDeclaration' ) {
105
105
elem . declarations . forEach ( ( hook : any ) => {
0 commit comments