@@ -24,9 +24,9 @@ export const throttle = (callback: Function, ms: number): Function => {
2424 let isOnCooldown = false ;
2525 let isCallQueued = false ;
2626
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)
3030 const throttledFunc = ( ) : any => {
3131 // CASE 1: In cooldown mode and we already have a function waiting to be executed,
3232 // so do nothing
@@ -40,7 +40,7 @@ export const throttle = (callback: Function, ms: number): Function => {
4040 }
4141
4242 // CASE 3: If we are ready to "fire":
43- // Execute the function, f, immediately
43+ // Execute the function callback immediately
4444 callback ( ) ;
4545 // Initiate a new cooldown period and reset the "call queue"
4646 isOnCooldown = true ;
@@ -51,7 +51,7 @@ export const throttle = (callback: Function, ms: number): Function => {
5151 const runAfterTimeout = ( ) : any => {
5252 if ( isCallQueued ) {
5353 isCallQueued = false ;
54- isOnCooldown = true ; // not needed I think
54+ isOnCooldown = true ;
5555 callback ( ) ;
5656 setTimeout ( runAfterTimeout , ms ) ;
5757 return ;
@@ -68,7 +68,7 @@ export const throttle = (callback: Function, ms: number): Function => {
6868// Helper function to grab the getters/setters from `elementType`
6969/**
7070 * @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
7272 * @returns An array of strings
7373 */
7474export const getHooksNames = ( elementType : string ) : Array < string > => {
@@ -95,11 +95,11 @@ export const getHooksNames = (elementType: string): Array<string> => {
9595 * Iterate through AST of every function declaration
9696 * Check within each function declaration if there are hook declarations */
9797 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 : [ ] ;
101101 // Traverse through the function's funcDecs and Expression Statements
102- body . forEach ( ( elem : any ) => {
102+ declarationBody . forEach ( ( elem : any ) => {
103103 // Hooks will always be contained in a variable declaration
104104 if ( elem . type === 'VariableDeclaration' ) {
105105 elem . declarations . forEach ( ( hook : any ) => {
0 commit comments