Skip to content

Commit 59f8fea

Browse files
authored
Merge pull request #27 from haejinjo/addDocumentation
Add documentation to backend
2 parents f23c59d + e09932f commit 59f8fea

File tree

12 files changed

+391
-557
lines changed

12 files changed

+391
-557
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@
4242
"Ergi Shehu",
4343
"Gabriela Jardim Aquino",
4444
"Gregory Panciera",
45+
"Haejin Jo",
46+
"Hien Nguyen",
47+
"Jack Crish",
4548
"Josh Kim",
4649
"Joshua Howard",
50+
"Kevin Fey",
4751
"Nathanael Wa Mwenze",
4852
"Prasanna Malla",
4953
"Rajeeb Banstola",
@@ -128,4 +132,4 @@
128132
"recoil": "0.0.10",
129133
"sankey": "^2.0.2"
130134
}
131-
}
135+
}

src/app/__tests__/Chart_deprecated_.test.tsx

Lines changed: 0 additions & 129 deletions
This file was deleted.

src/app/components/StateRoute.tsx

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface StateRouteProps {
4040
const StateRoute = (props: StateRouteProps) => {
4141
const { snapshot, hierarchy, snapshots, viewIndex } = props;
4242

43-
let isRecoil = snapshot.AtomsRelationship ? true : false;
43+
const isRecoil = snapshot.AtomsRelationship ? true : false;
4444
const [noRenderData, setNoRenderData] = useState(false);
4545

4646
// component map zoom state
@@ -50,29 +50,25 @@ const StateRoute = (props: StateRouteProps) => {
5050
k: 1,
5151
});
5252

53-
//Map
53+
// Map
5454
const renderComponentMap = () => {
5555
if (hierarchy) {
5656
return <ComponentMap viewIndex={viewIndex} snapshots={snapshots} x={x} y={y} k={k} setZoomState={setZoomState} />;
5757
}
5858
return <div className="noState">{NO_STATE_MSG}</div>;
5959
};
6060

61-
6261
// the hierarchy gets set on the first click in the page
6362
// when the page is refreshed we may not have a hierarchy, so we need to check if hierarchy was initialized
6463
// if true involk render chart with hierarchy
6564
const renderHistory = () => {
6665
if (hierarchy.children.length > 0) {
67-
6866
return <History hierarchy={hierarchy} />;
6967
}
70-
return <div className="noState">Application not compatible with history</div>;
68+
return <div className="noState">History graph will render on first state change</div>;
7169
};
7270

73-
const renderAtomsRelationship = () => {
74-
return <AtomsRelationship atomsRel={snapshot.AtomsRelationship} />;
75-
};
71+
const renderAtomsRelationship = () => <AtomsRelationship atomsRel={snapshot.AtomsRelationship} />;
7672

7773
// the hierarchy gets set on the first click in the page
7874
// when the page is refreshed we may not have a hierarchy, so we need to check if hierarchy was initialized
@@ -83,30 +79,16 @@ const StateRoute = (props: StateRouteProps) => {
8379
}
8480
return <div className="noState">{NO_STATE_MSG}</div>;
8581
};
86-
87-
let perfChart;
88-
if (true) {
89-
90-
perfChart = (
91-
<PerfView
92-
viewIndex={viewIndex}
93-
snapshots={snapshots}
94-
setNoRenderData={setNoRenderData}
95-
width={600}
96-
height={1000}
97-
/>
98-
);
99-
}
100-
101-
//This will intermitently block Recoil PerfCharts from rendering
102-
// else {
103-
// perfChart = (
104-
// <div className="no-data-message">
105-
// Application must be running in development mode in order to view
106-
// performance data
107-
// </div>
108-
// );
109-
// }
82+
83+
const perfChart = (
84+
<PerfView
85+
viewIndex={viewIndex}
86+
snapshots={snapshots}
87+
setNoRenderData={setNoRenderData}
88+
width={600}
89+
height={1000}
90+
/>
91+
);
11092

11193
const renderPerfView = () => <ErrorHandler>{perfChart}</ErrorHandler>;
11294

@@ -131,10 +113,13 @@ const StateRoute = (props: StateRouteProps) => {
131113
<NavLink className="router-link" activeClassName="is-active" to="/map">
132114
Map
133115
</NavLink>
134-
135-
{isRecoil && <NavLink className="router-link" activeClassName="is-active" to="/relationship">
136-
Relationships
137-
</NavLink>}
116+
117+
{isRecoil
118+
&& (
119+
<NavLink className="router-link" activeClassName="is-active" to="/relationship">
120+
Relationships
121+
</NavLink>
122+
)}
138123

139124
<NavLink
140125
className="router-link"

src/backend/__tests__/chromium.test.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/backend/helpers.ts

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// eslint-disable-next-line import/newline-after-import
1010
const acorn = require('acorn');
1111
const jsx = require('acorn-jsx');
12-
// import { acorn } from 'acorn'; // javascript parser
13-
// import { jsx } from 'acorn-jsx';
1412

1513
const JSXParser = acorn.Parser.extend(jsx());
1614

@@ -19,19 +17,37 @@ const JSXParser = acorn.Parser.extend(jsx());
1917
* @param f A function to throttle
2018
* @param t A number of milliseconds to use as throttling interval
2119
* @returns A function that limits input function, `f`, from being called more than once every `t` milliseconds
20+
*
2221
*/
2322
export const throttle = (f: Function, t: number): Function => {
24-
let isOnCooldown: boolean = false;
25-
let isCallQueued: boolean = false;
23+
// Initialize boolean flags for callback, throttledFunc
24+
let isOnCooldown = false;
25+
let isCallQueued = false;
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
2630
const throttledFunc = (): any => {
31+
// CASE 1: In cooldown mode and we already have a function waiting to be executed,
32+
// so do nothing
2733
if (isOnCooldown && isCallQueued) return;
34+
35+
// CASE 2: In cooldown mode, but we have no functions waiting to be executed,
36+
// so just make note that we now have a call waiting to be executed and return
2837
if (isOnCooldown) {
2938
isCallQueued = true;
3039
return;
3140
}
41+
42+
// CASE 3: If we are ready to "fire":
43+
// Execute the function, f, immediately
3244
f();
45+
// Initiate a new cooldown period and reset the "call queue"
3346
isOnCooldown = true;
3447
isCallQueued = false;
48+
49+
// Declare a function that checks whether we have
50+
// another function to be executed right after.
3551
const runAfterTimeout = (): any => {
3652
if (isCallQueued) {
3753
isCallQueued = false;
@@ -42,59 +58,58 @@ export const throttle = (f: Function, t: number): Function => {
4258
}
4359
isOnCooldown = false;
4460
};
61+
4562
setTimeout(runAfterTimeout, t);
4663
};
64+
4765
return throttledFunc;
4866
};
4967

5068
// Helper function to grab the getters/setters from `elementType`
51-
5269
/**
5370
* @method getHooksNames
54-
* @param elementType The fiber (whose hooks we want) `type`, A stringified function of the component the Fiber whose hooks we want corresponds to
55-
* @returns An array of strings
71+
* @param elementType The fiber `type`, A stringified function of the component the Fiber whose hooks we want corresponds to
72+
* @returns An array of strings
5673
*/
5774
export const getHooksNames = (elementType: string): Array<string> => {
5875
// Initialize empty object to store the setters and getter
5976
let ast: any;
6077
try {
6178
ast = JSXParser.parse(elementType);
6279
} catch (e) {
63-
console.error(`getHooksNames ERROR: Failed to parse elementType string:\n${elementType}`);
6480
return ['unknown'];
6581
}
6682

6783
const hooksNames: any = {};
6884

85+
// Begin search for hook names, only if ast has a body property.
6986
while (Object.hasOwnProperty.call(ast, 'body')) {
70-
let tsCount: number = 0; // Counter for the number of TypeScript hooks seen (to distinguish in masterState)
87+
let tsCount = 0; // Counter for the number of TypeScript hooks seen (to distinguish in masterState)
7188
ast = ast.body;
72-
const statements: Array<string> = [];
7389

90+
// Statements get all the names of the hooks. For example: useCount, useWildcard, ...
91+
const statements: Array<string> = [];
7492
/** All module exports always start off as a single 'FunctionDeclaration' type
7593
* Other types: "BlockStatement" / "ExpressionStatement" / "ReturnStatement"
7694
* Iterate through AST of every function declaration
7795
* Check within each function declaration if there are hook declarations */
78-
ast.forEach((functionDec) => {
96+
ast.forEach(functionDec => {
7997
let body: any;
80-
if (functionDec.expression && functionDec.expression.body)
81-
body = functionDec.expression.body.body;
98+
if (functionDec.expression && functionDec.expression.body) body = functionDec.expression.body.body;
8299
else body = functionDec.body ? functionDec.body.body : [];
83100
// Traverse through the function's funcDecs and Expression Statements
84101
body.forEach((elem: any) => {
102+
// Hooks will always be contained in a variable declaration
85103
if (elem.type === 'VariableDeclaration') {
86104
elem.declarations.forEach((hook: any) => {
87-
// * TypeScript hooks appear to have no "VariableDeclarator"
88-
// * with id.name of _useState, _useState2, etc...
89-
// * hook.id.type relevant for TypeScript applications
90-
// *
91-
// * Works for useState hooks
105+
// Parse destructured statements pair
92106
if (hook.id.type === 'ArrayPattern') {
93107
hook.id.elements.forEach((hook) => {
94108
statements.push(`_useWildcard${tsCount}`);
95109
statements.push(hook.name);
96110
tsCount += 1;
97111
});
112+
// Process hook function invocation ?
98113
} else {
99114
if (hook.init.object && hook.init.object.name) {
100115
const varName: any = hook.init.object.name;

0 commit comments

Comments
 (0)