Skip to content

Commit 5c39744

Browse files
authored
Merge pull request #4 from oslabs-beta/Emin
Emin
2 parents c2785e1 + b5e6763 commit 5c39744

File tree

3 files changed

+298
-322
lines changed

3 files changed

+298
-322
lines changed

src/backend/helpers.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
7474
export 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) => {

src/backend/index.ts

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
* 'reactime' module has a single export
88
* @function linkFiber
99
*/
10-
10+
// regenerator runtime supports async functionality
1111
import 'regenerator-runtime/runtime';
1212
import linkFiberStart from './linkFiber';
1313
import timeJumpStart from './timeJump';
1414
import {
15-
Snapshot, Mode, SnapshotNode, MsgData,
15+
Snapshot, Mode, MsgData,
1616
} from './types/backendTypes';
1717

1818
// * State snapshot object initialized here
@@ -26,57 +26,26 @@ const mode: Mode = {
2626
paused: false,
2727
};
2828

29+
// linkFiber is now assigned the default function exported from the file linkFiber.ts
2930
const linkFiber = linkFiberStart(snapShot, mode);
31+
// timeJump is now assigned the default function exported from the file timeJump.ts
3032
const timeJump = timeJumpStart(snapShot, mode);
3133

3234
// * Event listener for time-travel actions
3335
window.addEventListener('message', ({ data: { action, payload } }: MsgData) => {
3436
switch (action) {
3537
case 'jumpToSnap':
36-
timeJump(payload, true); // * This sets state with given payload
37-
// Get the pathname from payload and add new entry to browser history
38-
// MORE: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
39-
// try to modify workInProgress tree from here
40-
// window.history.pushState('', '', getRouteURL(payload));
38+
timeJump(payload, true); // * This sets state with given payloa
4139
break;
40+
4241
case 'setPause':
4342
mode.paused = payload;
4443
break;
45-
// maybe this isn't work react cohort 45
46-
// case 'onHover':
47-
// if (Array.isArray(payload)) {
48-
// for (let i = 0; i < payload.length; i + 1) {
49-
// const element = document.getElementById(payload[i]);
50-
// if (element !== null) {
51-
// element.style.backgroundColor = '#C0D9D9';
52-
// }
53-
// }
54-
// } else {
55-
// const element: HTMLElement = document.querySelector(`.${payload}`);
56-
// if (element !== null) {
57-
// element.style.backgroundColor = '#C0D9D9';
58-
// }
59-
// }
60-
// break;
61-
// // maybe this isn't work react cohort 45
62-
// case 'onHoverExit':
63-
// if (Array.isArray(payload)) {
64-
// for (let i = 0; i < payload.length; i++) {
65-
// const element: HTMLElement = document.querySelector(`.${payload}`);
66-
// if (element !== null) {
67-
// element.style.backgroundColor = '';
68-
// }
69-
// }
70-
// } else {
71-
// const element: HTMLElement = document.querySelector(`.${payload}`);
72-
// if (element !== null) {
73-
// element.style.backgroundColor = '';
74-
// }
75-
// }
76-
// break;
44+
7745
default:
7846
break;
7947
}
8048
});
81-
// connect to dev tools and new fiber
49+
// connect to dev tools and new fiber,
50+
// invokes anonymous function from linkFiber.ts set to linkFiber on line 30
8251
linkFiber();

0 commit comments

Comments
 (0)