Skip to content

Commit 991fea9

Browse files
authored
Merge pull request #3 from kevinfey/recoilAdded
Changed helpers.js to allow for recoil state to flow to Reactime App
2 parents c788fea + fa3bf55 commit 991fea9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/backend/helpers.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const throttle = (f, t) => {
4545
};
4646

4747
// Helper function to grab the getters/setters from `elementType`
48-
export const getHooksNames = elementType => {
48+
export const getHooksNames = (elementType) => {
4949
// Initialize empty object to store the setters and getter
5050
let ast;
5151
try {
@@ -65,21 +65,22 @@ export const getHooksNames = elementType => {
6565
* Other types: "BlockStatement" / "ExpressionStatement" / "ReturnStatement"
6666
* Iterate through AST of every function declaration
6767
* Check within each function declaration if there are hook declarations */
68-
ast.forEach(functionDec => {
68+
ast.forEach((functionDec) => {
6969
let body;
70-
if (functionDec.expression && functionDec.expression.body) body = functionDec.expression.body.body;
70+
if (functionDec.expression && functionDec.expression.body)
71+
body = functionDec.expression.body.body;
7172
else body = functionDec.body ? functionDec.body.body : [];
7273
// Traverse through the function's funcDecs and Expression Statements
73-
body.forEach(elem => {
74+
body.forEach((elem) => {
7475
if (elem.type === 'VariableDeclaration') {
75-
elem.declarations.forEach(hook => {
76+
elem.declarations.forEach((hook) => {
7677
// * TypeScript hooks appear to have no "VariableDeclarator"
7778
// * with id.name of _useState, _useState2, etc...
7879
// * hook.id.type relevant for TypeScript applications
7980
// *
8081
// * Works for useState hooks
8182
if (hook.id.type === 'ArrayPattern') {
82-
hook.id.elements.forEach(hook => {
83+
hook.id.elements.forEach((hook) => {
8384
statements.push(hook.name);
8485
// * Unshift a wildcard name to achieve similar functionality as before
8586
statements.unshift(`_useWildcard${tsCount}`);
@@ -92,7 +93,9 @@ export const getHooksNames = elementType => {
9293
hooksNames[varName] = hook.id.name;
9394
}
9495
}
95-
statements.push(hook.id.name);
96+
if (hook.id.name !== undefined) {
97+
statements.push(hook.id.name);
98+
}
9699
}
97100
});
98101
}

0 commit comments

Comments
 (0)