Skip to content

Commit 89e90cb

Browse files
committed
working on createTree state display
1 parent 751c65b commit 89e90cb

File tree

5 files changed

+148
-95
lines changed

5 files changed

+148
-95
lines changed

src/backend/__tests__/masterTree.test.tsx

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
allowedComponentTypes,
2424
nextJSDefaultComponent,
2525
remixDefaultComponents,
26+
exclude,
2627
} from '../models/filterConditions';
2728
import deepCopy from './ignore/deepCopy';
2829

@@ -135,12 +136,20 @@ describe('master tree tests', () => {
135136
});
136137
});
137138
describe('Display component props information', () => {
138-
const memoizedProps = {
139+
const memoizedProps: {
140+
propVal: number;
141+
propFunc: Function;
142+
propObj: { [key: string]: any };
143+
} = {
139144
propVal: 0,
140145
propFunc: jest.fn,
141146
propObj: { dummy: 'dummy' },
142147
};
143-
const props = {
148+
const props: {
149+
propVal: number;
150+
propFunc: 'function';
151+
propObj: string;
152+
} = {
144153
propVal: 0,
145154
propFunc: 'function',
146155
propObj: JSON.stringify({ dummy: 'dummy' }),
@@ -190,24 +199,67 @@ describe('master tree tests', () => {
190199
expect(routerTree).toEqual(treeRoot);
191200
}
192201
});
193-
194-
it('should display props information of multiple components', () => {
195-
mockChildNode.memoizedProps = memoizedProps;
202+
it('should exclude reserved props name', () => {
196203
(mockChildTree.componentData as ComponentData).props = props;
197204
treeRoot.children.push(mockChildTree);
205+
206+
for (let propName of exclude) {
207+
componentActionsRecord.clear(); // reset index counts for component actions
208+
mockChildNode.memoizedProps = { ...memoizedProps, [propName]: 'anything' };
209+
const tree = createTree(mockChildNode);
210+
expect(tree).toEqual(treeRoot);
211+
}
212+
});
213+
it('should skip circular props', () => {
214+
mockChildNode.memoizedProps = {
215+
...memoizedProps,
216+
cir: mockChildNode,
217+
noCir: 'Not a circular props',
218+
};
219+
(mockChildTree.componentData as ComponentData).props = {
220+
...props,
221+
noCir: 'Not a circular props',
222+
};
223+
treeRoot.children.push(mockChildTree);
224+
225+
const tree = createTree(mockChildNode);
226+
expect(tree).toEqual(treeRoot);
227+
});
228+
229+
xit('should display props information of multiple components', () => {
230+
// Trim the root to get position of mockFiber for append child and sibiling
231+
const mockFiberTreeTrimRoot = mockFiberTree.children[0];
232+
233+
// Add child(class) component with props:
234+
mockChildNode.memoizedProps = { ...memoizedProps, name: 'child' };
235+
(mockChildTree.componentData as ComponentData).props = { ...props, name: 'child' };
236+
(mockChildTree.componentData as ComponentData).index = 0;
237+
mockFiberTreeTrimRoot.children.push(mockChildTree);
238+
239+
// Add sibiling(functional) component with props:
198240
mockSiblingNode.memoizedProps = { ...memoizedProps, name: 'sibling' };
199241
(mockSiblingTree.componentData as ComponentData).props = { ...props, name: 'sibling' };
200-
treeRoot.children.push(mockSiblingTree);
242+
(mockSiblingTree.componentData as ComponentData).hooksIndex = [1];
243+
mockFiberTreeTrimRoot.children.push(mockSiblingTree);
201244

245+
// Modify mockFiberNode to have 2 children: mockChildNode & mockSibilngNode
202246
mockFiberNode.child = mockChildNode;
203-
mockFiberNode.sibling = mockSiblingNode;
247+
mockFiberNode.child.sibling = mockSiblingNode;
248+
204249
const tree = createTree(mockFiberNode);
205-
const children = tree.children;
206-
expect(children.length).toEqual(2);
207-
expect(children[0]).toEqual(mockChildTree);
208-
expect(children[1]).toEqual(mockSiblingTree);
209-
expect(tree).toEqual(treeRoot);
250+
expect(tree).toEqual(mockFiberTree);
251+
});
252+
});
253+
describe('Display component states information', () => {
254+
it('should display functional state information', () => {
255+
mockChildNode.stateNode = {
256+
257+
}
210258
});
259+
xit('should display class state information', () => {});
260+
});
261+
xdescribe('Replace fromLinkFiber class value', () => {
262+
it('NEED UNDERSTANDING OF WHY FROMLINKFIBER IS NEEDED TO MAKE TESTING', () => {});
211263
});
212264
});
213265

src/backend/controllers/createTree/createTree.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,10 @@ export default function createTree(currentFiberNode: Fiber): Tree {
234234
// TODO: Refactor this, this is currently being used for Tree & Diff tabs
235235
newState = componentData.hooksState;
236236
} catch (err) {
237-
console.log('ERROR: Failed Element during JSX parsing', {
237+
console.log({
238+
Message: 'Error in createTree during obtaining state from functionalComponent',
238239
componentName,
240+
err,
239241
});
240242
}
241243
}

src/backend/controllers/createTree/statePropExtractors.ts

Lines changed: 4 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7,85 +7,12 @@ import {
77
// object with tree structure
88
Fiber,
99
} from '../../types/backendTypes';
10+
import { exclude } from '../../models/filterConditions';
1011
// TODO: Determine what Component Data Type we are sending back for state, context, & props
1112
type ReactimeData = {
1213
[key: string]: any;
1314
};
14-
/**
15-
* A set of excluded props and variable name
16-
*/
17-
const exclude = new Set([
18-
'alternate',
19-
'basename',
20-
'baseQueue',
21-
'baseState',
22-
'child',
23-
'childLanes',
24-
'children',
25-
'Consumer',
26-
'context',
27-
'create',
28-
'deps',
29-
'dependencies',
30-
'destroy',
31-
'dispatch',
32-
'location',
33-
'effects',
34-
'element',
35-
'elementType',
36-
'firstBaseUpdate',
37-
'firstEffect',
38-
'flags',
39-
'get key',
40-
'getState',
41-
'hash',
42-
'key',
43-
'lanes',
44-
'lastBaseUpdate',
45-
'lastEffect',
46-
'liftedStore',
47-
'navigator',
48-
'memoizedState',
49-
'mode',
50-
'navigationType',
51-
'next',
52-
'nextEffect',
53-
'pending',
54-
'parentSub',
55-
'pathnameBase',
56-
'pendingProps',
57-
'Provider',
58-
'updateQueue',
59-
'ref',
60-
'replaceReducer',
61-
'responders',
62-
'return',
63-
'route',
64-
'routeContext',
65-
'search',
66-
'shared',
67-
'sibling',
68-
'state',
69-
'store',
70-
'subscribe',
71-
'subscription',
72-
'stateNode',
73-
'tag',
74-
'type',
75-
'_calculateChangedBits',
76-
'_context',
77-
'_currentRenderer',
78-
'_currentRenderer2',
79-
'_currentValue',
80-
'_currentValue2',
81-
'_owner',
82-
'_self',
83-
'_source',
84-
'_store',
85-
'_threadCount',
86-
'$$typeof',
87-
'@@observable',
88-
]);
15+
8916
// ------------FILTER DATA FROM REACT DEV TOOL && CONVERT TO STRING-------------
9017
/**
9118
* This function receives raw Data from REACT DEV TOOL and filter the Data based on the exclude list. The filterd data is then converted to string (if applicable) before being sent to reacTime front end.
@@ -218,11 +145,7 @@ export function getHooksNames(elementType: string): { hookName: string; varName:
218145
let AST: any;
219146
try {
220147
AST = JSXParser.parse(elementType).body;
221-
} catch (e) {
222-
throw Error('Error occurs at helpers getHooksName.ts Cannot parse functional component.');
223-
}
224-
// Begin search for hook names, only if ast has a body property.
225-
try {
148+
// Begin search for hook names, only if ast has a body property.
226149
// Statements get all the names of the hooks. For example: useCount, useWildcard, ...
227150
const statements: { hookName: string; varName: string }[] = [];
228151
/** All module exports always start off as a single 'FunctionDeclaration' type
@@ -261,7 +184,7 @@ export function getHooksNames(elementType: string): { hookName: string; varName:
261184
});
262185
return statements;
263186
} catch (err) {
264-
throw new Error();
187+
throw new Error('getHooksNameError' + err.message);
265188
}
266189
}
267190

src/backend/models/filterConditions.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,79 @@ export const remixDefaultComponents = new Set([
7272
'Scripts',
7373
'LiveReload2',
7474
]);
75+
76+
export /**
77+
* A set of excluded props and variable name
78+
*/
79+
const exclude = new Set([
80+
'alternate',
81+
'basename',
82+
'baseQueue',
83+
'baseState',
84+
'child',
85+
'childLanes',
86+
'children',
87+
'Consumer',
88+
'context',
89+
'create',
90+
'deps',
91+
'dependencies',
92+
'destroy',
93+
'dispatch',
94+
'location',
95+
'effects',
96+
'element',
97+
'elementType',
98+
'firstBaseUpdate',
99+
'firstEffect',
100+
'flags',
101+
'get key',
102+
'getState',
103+
'hash',
104+
'key',
105+
'lanes',
106+
'lastBaseUpdate',
107+
'lastEffect',
108+
'liftedStore',
109+
'navigator',
110+
'memoizedState',
111+
'mode',
112+
'navigationType',
113+
'next',
114+
'nextEffect',
115+
'pending',
116+
'parentSub',
117+
'pathnameBase',
118+
'pendingProps',
119+
'Provider',
120+
'updateQueue',
121+
'ref',
122+
'replaceReducer',
123+
'responders',
124+
'return',
125+
'route',
126+
'routeContext',
127+
'search',
128+
'shared',
129+
'sibling',
130+
'state',
131+
'store',
132+
'subscribe',
133+
'subscription',
134+
'stateNode',
135+
'tag',
136+
'type',
137+
'_calculateChangedBits',
138+
'_context',
139+
'_currentRenderer',
140+
'_currentRenderer2',
141+
'_currentValue',
142+
'_currentValue2',
143+
'_owner',
144+
'_self',
145+
'_source',
146+
'_store',
147+
'_threadCount',
148+
'$$typeof',
149+
'@@observable',
150+
]);

src/backend/types/backendTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export interface ComponentData {
6262
actualStartTime?: number;
6363
selfBaseDuration?: number;
6464
treeBaseDuration?: number;
65-
props: {};
65+
props: { [key: string]: any };
6666
context: {};
6767
state: {} | null;
6868
hooksState: {} | null;

0 commit comments

Comments
 (0)