Skip to content

Commit 96ca6ec

Browse files
committed
Merge branch 'master' of https://github.com/oslabs-beta/reactime
2 parents 836f342 + 29b29b7 commit 96ca6ec

File tree

5 files changed

+64
-33
lines changed

5 files changed

+64
-33
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/components/Map.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ const Map = (props) => {
1212
console.log('MAP SNAPSHOT', snapshot);
1313

1414
// set the heights and width of the tree to be passed into treeMap function
15-
const width: number = 600;
16-
const height: number = 1100;
15+
const width: number = 1100;
16+
const height: number = 600;
1717

1818
// this state allows the canvas to stay at the zoom level on multiple re-renders
1919
const [{ x, y, k }, setZoomState]: any = useState({ x: 0, y: 0, k: 0 });
2020

2121
useEffect(() => {
2222
setZoomState(d3.zoomTransform(d3.select('#canvas').node()));
23-
}, [snapshot]);
23+
}, [snapshot.children]);
2424

2525
// this only clears the canvas if Visualizer is already rendered on the extension
2626
useEffect(() => {
@@ -31,9 +31,9 @@ const Map = (props) => {
3131
.select('#canvas')
3232
.attr('width', width)
3333
.attr('height', height);
34-
3534
// creating a pseudo-class for reusability
3635
const g: any = svgContainer
36+
3737
.append('g')
3838
.attr('transform', `translate(${x}, ${y}), scale(${k})`); // sets the canvas to the saved zoomState
3939

@@ -46,13 +46,12 @@ const Map = (props) => {
4646
// childrenArr.push(el)
4747
// );
4848
// }
49-
49+
5050
// console.log('CHILDREN', childrenArr);
5151

5252
const appState: any = {
5353
name: ' Root',
5454
// pass in parsed data here
55-
// call the helper function passing in the most recent snapshot
5655
children: snapshot.children,
5756
};
5857

@@ -96,6 +95,7 @@ const Map = (props) => {
9695
// returns a flat array of objects containing all the nodes and their information
9796
// renders nodes onto the canvas
9897
let nodes: any = hierarchyNodes.descendants();
98+
console.log("NODES",nodes)
9999

100100
// const node is used to create all the nodes
101101
// this segment places all the nodes on the canvas
@@ -111,13 +111,16 @@ const Map = (props) => {
111111
.attr('class', 'atomNodes');
112112

113113
// for each node that got created, append a circle element
114-
node.append('circle').attr('fill', '#c300ff').attr('r', 50);
114+
node
115+
.append('circle')
116+
.attr('fill', (d: any) => (d.children ? '#3214db' : '#c300ff'))
117+
.attr('r', 50);
115118

116119
// for each node that got created, append a text element that displays the name of the node
117120
node
118121
.append('text')
119122
.attr('dy', '.31em')
120-
.attr('x', (d: any) => (d.children ? -75 : 75))
123+
.attr('x', (d: any) => (d.children ? -50 : 50))
121124
.attr('text-anchor', (d: any) => (d.children ? 'end' : 'start'))
122125
.text((d: any) => d.data.name)
123126
.style('font-size', `2rem`)
@@ -136,9 +139,10 @@ const Map = (props) => {
136139
.append('text')
137140
.text(JSON.stringify(d.data, undefined, 2))
138141
.style('fill', 'white')
139-
.attr('x', 75)
140-
.attr('y', 60)
142+
.attr('x', -999)
143+
.attr('y', 100)
141144
.style('font-size', '3rem')
145+
.style('text-align', 'center')
142146
.attr('stroke', '#646464')
143147
.attr('id', `popup${i}`);
144148
}
@@ -166,7 +170,7 @@ const Map = (props) => {
166170
[0, 0],
167171
[width, height],
168172
])
169-
.scaleExtent([0, 8])
173+
.scaleExtent([0, 5])
170174
.on('zoom', zoomed)
171175
);
172176

@@ -192,7 +196,6 @@ const Map = (props) => {
192196
}
193197
});
194198

195-
console.log('208');
196199
return (
197200
<div data-testid="canvas">
198201
<div className="Visualizer">

src/app/components/PerfView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const PerfView = (props: PerfViewProps) => {
4040
// snapshots.forEach((snapshot) => snapshot.children[0].children.shift());
4141
// console.log('SNAPSHOTS -------------------------->', snapshots);
4242
// Figure out which snapshot index to use
43+
4344
let indexToDisplay: number | null = null;
4445
if (viewIndex < 0) indexToDisplay = snapshots.length - 1;
4546
else indexToDisplay = viewIndex;

src/backend/linkFiber.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
9191
component: memoizedState.queue,
9292
state: memoizedState.memoizedState,
9393
});
94+
9495
}
9596
memoizedState =
9697
memoizedState.next !== memoizedState ? memoizedState.next : null;
@@ -177,6 +178,7 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
177178
state: memoizedProps,
178179
});
179180
}
181+
180182
}
181183
memoizedState =
182184
memoizedState.next !== memoizedState ? memoizedState.next : null;
@@ -197,18 +199,29 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
197199
// which includes the dispatch() function we use to change their state.
198200
const hooksStates = traverseRecoilHooks(memoizedState);
199201
hooksStates.forEach((state, i) => {
202+
200203
hooksIndex = componentActionsRecord.saveNew(
201204
state.state,
202205
state.component
203206
);
204207
componentData.hooksIndex = hooksIndex;
205208

209+
// if (newState && newState.hooksState) {
210+
// newState.hooksState.push({ [hooksNames[i]]: state.state });
211+
// } else if (newState) {
212+
// newState.hooksState = [{ [hooksNames[i]]: state.state }];
213+
// } else {
214+
// newState = { hooksState: [] };
215+
// newState.hooksState.push({ [hooksNames[i]]: state.state });
216+
// }
217+
218+
//improves tree visualization but breaks jump
206219
if (newState && newState.hooksState) {
207220
newState.push(state.state);
208221
} else if (newState) {
209-
newState = [ state.state ];
222+
newState = [state.state];
210223
} else {
211-
newState.push(state.state );
224+
newState.push(state.state);
212225
}
213226
componentFound = true;
214227
});
@@ -217,8 +230,13 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
217230

218231
// Check if node is a hooks useState function
219232
//REGULAR REACT HOOKS
220-
if (memoizedState && (tag === 0 || tag === 1 || tag === 2 || tag === 10) && isRecoil === false) {
233+
if (
234+
memoizedState &&
235+
(tag === 0 || tag === 1 || tag === 2 || tag === 10) &&
236+
isRecoil === false
237+
) {
221238
if (memoizedState.queue) {
239+
222240
// Hooks states are stored as a linked list using memoizedState.next,
223241
// so we must traverse through the list and get the states.
224242
// We then store them along with the corresponding memoizedState.queue,
@@ -302,6 +320,7 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
302320
snap.tree = createTree(current);
303321
}
304322

323+
305324
sendSnapshot();
306325
}
307326

src/backend/timeJump.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,44 @@ export default (origin, mode) => {
3333
if (!target) return;
3434

3535
if (target.state === 'stateless') {
36-
target.children.forEach(child => jump(child));
36+
target.children.forEach((child) => jump(child));
3737
return;
3838
}
39-
const component = componentActionsRecord.getComponentByIndex(target.componentData.index);
39+
const component = componentActionsRecord.getComponentByIndex(
40+
target.componentData.index
41+
);
4042
if (component && component.setState) {
41-
component.setState(prevState => {
42-
Object.keys(prevState).forEach(key => {
43-
if (target.state[key] === undefined) {
44-
target.state[key] = undefined;
45-
}
46-
});
47-
return target.state;
48-
// Iterate through new children after state has been set
49-
}, () => target.children.forEach(child => jump(child)));
43+
component.setState(
44+
(prevState) => {
45+
Object.keys(prevState).forEach((key) => {
46+
if (target.state[key] === undefined) {
47+
target.state[key] = undefined;
48+
}
49+
});
50+
return target.state;
51+
// Iterate through new children after state has been set
52+
},
53+
() => target.children.forEach((child) => jump(child))
54+
);
5055
}
5156

5257
// console.log('TARGET', target);
5358
// Check for hooks state and set it with dispatch()
5459
if (target.state && target.state.hooksState) {
55-
target.state.hooksState.forEach(hook => {
56-
const hooksComponent = componentActionsRecord.getComponentByIndex(target.componentData.hooksIndex);
60+
target.state.hooksState.forEach((hook) => {
61+
const hooksComponent = componentActionsRecord.getComponentByIndex(
62+
target.componentData.hooksIndex
63+
);
5764
const hookState = Object.values(hook);
65+
console.log('target', target);
5866
if (hooksComponent && hooksComponent.dispatch) {
59-
// console.log('attempt to dispatch this', hooksComponent, hookState[0]);
67+
6068
hooksComponent.dispatch(hookState[0]);
6169
}
6270
});
6371
}
6472

65-
target.children.forEach(child => {
73+
target.children.forEach((child) => {
6674
if (!circularComponentTable.has(child)) {
6775
circularComponentTable.add(child);
6876
jump(child);

0 commit comments

Comments
 (0)