Skip to content

Commit 0ad244d

Browse files
committed
Merge with master after PRs 25 and 26
2 parents 2ae6d73 + f23c59d commit 0ad244d

File tree

8 files changed

+98
-105
lines changed

8 files changed

+98
-105
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
"react-dom": "^16.13.1",
125125
"react-google-chart": "^0.1.2",
126126
"react-google-charts": "^3.0.15",
127+
"react-google-charts-ts": "^0.1.1",
127128
"react-html-parser": "^2.0.2",
128129
"react-json-tree": "^0.11.2",
129130
"react-router-dom": "^5.2.0",

src/app/components/AtomsRelationship.jsx

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
1-
import React, { Component, useEffect, useState } from 'react';
2-
// import * as d3 from 'd3';
3-
// import {sankey} from 'sankey';
4-
import { Chart } from 'react-google-charts';
5-
6-
/**
7-
* @method maked3Tree :Creates a new D3 Tree
8-
*/
1+
import React, { Component, useEffect, useState, Fragment } from 'react';
2+
import { Chart } from 'react-google-charts'
93

104
function AtomsRelationship(props) {
11-
console.log('Props', props.atomsRel);
12-
135
const {atomsRel} = props
146

7+
const atomsAndComp = atomsRel.filter(e => e[2] !== 'atoms and selectors').map(e => {
8+
let copy = [...e];
9+
copy[2] = 1;
10+
return [...copy]
11+
});
12+
13+
const atomsAndSelectors = atomsRel.filter(e => e[2] === 'atoms and selectors').map(e => {
14+
let copy = [...e];
15+
copy[2] = 1;
16+
return [...copy]
17+
});
18+
19+
const copyatomsRel = atomsRel.map(e => { let copy = [...e]; copy[2] = 1; return copy; });
20+
const [atoms, setAtoms] = useState([...copyatomsRel]);
21+
const [atomAndSelectorCheck, setAtomAndSelectorCheck] = useState(false);
22+
const [atomAndCompCheck, setAtomAndCompCheck] = useState(false);
23+
24+
useEffect( () => {
25+
if ((!atomAndSelectorCheck && !atomAndCompCheck) || (atomAndSelectorCheck && atomAndCompCheck)) {
26+
setAtoms(copyatomsRel);
27+
} else if (atomAndSelectorCheck) {
28+
setAtoms(atomsAndSelectors);
29+
} else {
30+
setAtoms(atomsAndComp);
31+
}
32+
}, [atomAndSelectorCheck, atomAndCompCheck, props])
1533

1634
return (
17-
<div className="history-d3-container" id="atomsContainer">
18-
{atomsRel && (
35+
<div className="history-d3-container">
36+
{atoms && (
37+
<Fragment>
1938
<Chart
2039
width={'100%'}
2140
height={'100%'}
@@ -49,9 +68,19 @@ function AtomsRelationship(props) {
4968
tooltip: { textStyle: { color: 'white', fontSize: 0.1, }},
5069
}}
5170
loader={<div>Loading Chart</div>}
52-
data={[['Atom', 'Selector', ''], ...atomsRel]}
71+
data={[['Atom', 'Selector', ''], ...atoms]}
5372
rootProps={{ 'data-testid': '1' }}
54-
/>)}
73+
/>
74+
<div>
75+
<input type="checkbox" id='atomscomps' onClick={e => setAtomAndCompCheck(atomAndCompCheck ? false: true)}/>
76+
<label htmlFor="atomscomps"> Only Show Atoms (or Selectors) and Components </label>
77+
<input type="checkbox" id='atomsselectors' onClick={e => setAtomAndSelectorCheck(atomAndSelectorCheck ? false : true)} />
78+
<label htmlFor="atomsselectors"> Only Show Atoms and Selectors </label>
79+
</div>
80+
</Fragment>
81+
)
82+
83+
}
5584
</div>
5685
);
5786
}

src/app/components/History.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ function History(props) {
140140
tooltipDiv.transition().duration(50).style('opacity', 0.9);
141141

142142
if (d.data.stateSnapshot.children[0].name === 'RecoilRoot') {
143-
console.log('enter');
144143
isRecoil = true;
145144
}
146145
if (!isRecoil) {

src/app/components/PerfView.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,11 @@ const PerfView = (props: PerfViewProps) => {
3535
let { snapshots } = props;
3636
const adjustedSize = Math.min(width, height);
3737
const svgRef = useRef(null);
38-
39-
//NEEDS REWRITE FOR RECOIL
40-
// snapshots.forEach((snapshot) => snapshot.children[0].children.shift());
41-
// console.log('SNAPSHOTS -------------------------->', snapshots);
42-
// Figure out which snapshot index to use
4338

4439
let indexToDisplay: number | null = null;
4540
if (viewIndex < 0) indexToDisplay = snapshots.length - 1;
4641
else indexToDisplay = viewIndex;
4742

48-
//console.log('SNAPSHOTS IN PERF VIEW', snapshots);
49-
//console.log('VIEW INDEX', indexToDisplay);
50-
5143
// Set up color scaling function
5244
const colorScale = d3
5345
.scaleOrdinal()

src/app/components/StateRoute.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ interface StateRouteProps {
3939

4040
const StateRoute = (props: StateRouteProps) => {
4141
const { snapshot, hierarchy, snapshots, viewIndex } = props;
42-
// let isRecoil = true;
43-
// console.log('snapshot', snapshot)
44-
// console.log(snapshot.AtomsRelationship)
42+
4543
let isRecoil = snapshot.AtomsRelationship ? true : false;
4644
const [noRenderData, setNoRenderData] = useState(false);
4745

@@ -66,10 +64,9 @@ const StateRoute = (props: StateRouteProps) => {
6664
// if true involk render chart with hierarchy
6765
const renderHistory = () => {
6866
if (hierarchy.children.length > 0) {
69-
7067
return <History hierarchy={hierarchy} />;
7168
}
72-
return <div className="noState">Application not compatible with history</div>;
69+
return <div className="noState">History graph will render on first state change</div>;
7370
};
7471

7572
const renderAtomsRelationship = () => {
@@ -85,10 +82,10 @@ const StateRoute = (props: StateRouteProps) => {
8582
}
8683
return <div className="noState">{NO_STATE_MSG}</div>;
8784
};
88-
85+
8986
let perfChart;
9087
if (true) {
91-
88+
9289
perfChart = (
9390
<PerfView
9491
viewIndex={viewIndex}
@@ -133,9 +130,9 @@ const StateRoute = (props: StateRouteProps) => {
133130
<NavLink className="router-link" activeClassName="is-active" to="/map">
134131
Map
135132
</NavLink>
136-
133+
137134
{isRecoil && <NavLink className="router-link" activeClassName="is-active" to="/relationship">
138-
Relationships
135+
Relationships
139136
</NavLink>}
140137

141138
<NavLink

src/app/components/Tree.tsx

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,7 @@
66
import React from 'react';
77
import JSONTree from 'react-json-tree';
88

9-
10-
11-
12-
13-
14-
15-
16-
17-
18-
19-
20-
21-
22-
23-
24-
25-
const colors = {
9+
const colors = {
2610
scheme: 'paraiso',
2711
author: 'jan t. sott',
2812
base00: '#2f1e2e',
@@ -40,21 +24,30 @@ const colors = {
4024
base0C: '#5bc4bf',
4125
base0D: '#06b6ef',
4226
base0E: '#815ba4',
43-
base0F: '#e96ba8'
27+
base0F: '#e96ba8',
4428
};
4529

46-
const getItemString = (type, data:{state?:object|string, name:string, children:[]}) => {
30+
const getItemString = (
31+
type,
32+
data: { state?: object | string; name: string; children: [] }
33+
) => {
4734
if (data && data.name) {
4835
return <span>{data.name}</span>;
4936
}
5037
return <span />;
5138
};
5239

5340
interface TreeProps {
54-
snapshot: { name?: string; componentData?: object; state?: string | object; stateSnaphot?: object; children?: any[]; };
41+
snapshot: {
42+
name?: string;
43+
componentData?: object;
44+
state?: string | object;
45+
stateSnaphot?: object;
46+
children?: any[];
47+
};
5548
}
5649

57-
const Tree = (props:TreeProps) => {
50+
const Tree = (props: TreeProps) => {
5851
const { snapshot } = props;
5952

6053
return (
@@ -65,8 +58,8 @@ const Tree = (props:TreeProps) => {
6558
theme={{ extend: colors, tree: () => ({ className: 'json-tree' }) }}
6659
shouldExpandNode={() => true}
6760
getItemString={getItemString}
68-
labelRenderer={(raw:any[]) => {
69-
return (typeof raw[0] !== 'number' ? <span>{raw[0]}</span> : null);
61+
labelRenderer={(raw: any[]) => {
62+
return typeof raw[0] !== 'number' ? <span>{raw[0]}</span> : null;
7063
}}
7164
/>
7265
)}

src/backend/linkFiber.ts

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -27,48 +27,31 @@ declare global {
2727
__REACT_DEVTOOLS_GLOBAL_HOOK__?: any;
2828
}
2929
}
30-
3130
let fiberRoot = null;
32-
let isRecoil = false;
3331
let doWork = true;
3432
const circularComponentTable = new Set();
3533
let allAtomsRelationship = [];
34+
let isRecoil = false;
35+
36+
// Simple check for whether our target app uses Recoil
37+
if (window[`$recoilDebugStates`]) {
38+
isRecoil = true;
39+
}
3640

3741
function getRecoilState(): any {
38-
// get the last state snapshot
3942
const RecoilSnapshotsLength = window[`$recoilDebugStates`].length;
4043
const lastRecoilSnapshot = window[`$recoilDebugStates`][RecoilSnapshotsLength - 1];
41-
console.log(lastRecoilSnapshot);
42-
43-
// get all atom - selector pairs, and save them as nodes
44-
// in the from to weight format
4544
const nodeToNodeSubs = lastRecoilSnapshot.nodeToNodeSubscriptions;
46-
let nodeToNodeSubsKeys = lastRecoilSnapshot.nodeToNodeSubscriptions.keys();
45+
const nodeToNodeSubsKeys = lastRecoilSnapshot.nodeToNodeSubscriptions.keys();
4746
nodeToNodeSubsKeys.forEach(
4847
node => {
4948
nodeToNodeSubs.get(node).forEach(
50-
nodeSubs => allAtomsRelationship.push([node, nodeSubs, 1])
51-
)
49+
nodeSubs => allAtomsRelationship.push([node, nodeSubs, 'atoms and selectors'])
50+
);
5251
}
53-
)
54-
55-
// get all atom - component pairs, and save them as nodes
56-
// in the from to weight format
57-
58-
// const nodeToCompSubs = lastRecoilSnapshot.nodeToComponentSubscriptions;
59-
// console.log(nodeToCompSubs);
60-
// let nodeToCompSubsKeys = lastRecoilSnapshot.nodeToComponentSubscriptions.keys();
61-
// nodeToCompSubsKeys.forEach(
62-
// node => {
63-
// console.log(node);
64-
// // nodeToCompSubsKeys.get(node).forEach(
65-
// // nodeSubs => allAtomsRelationship.push([node, nodeSubs, 2])
66-
// // )
67-
// }
68-
// )
52+
);
6953
}
7054

71-
7255
/**
7356
* @method sendSnapshot
7457
* @param snap The current snapshot
@@ -85,15 +68,11 @@ function sendSnapshot(snap: Snapshot, mode: Mode): void {
8568
snap.tree = new Tree('root', 'root');
8669
}
8770

88-
const payload = snap.tree.cleanTreeCopy(); // snap.tree.getCopy();
89-
// console.log('here is payload', payload);
90-
// console.log('here is recoil state', window[`$recoilDebugStates`]);
91-
isRecoil ? getRecoilState() : ' ';
92-
93-
console.log('all atoms state', allAtomsRelationship)
94-
// payload.recoilState = window[`$recoilDebugStates`];
95-
96-
isRecoil ? payload.AtomsRelationship = allAtomsRelationship : ' ';
71+
const payload = snap.tree.cleanTreeCopy();
72+
if (isRecoil) {
73+
getRecoilState();
74+
payload.AtomsRelationship = allAtomsRelationship;
75+
}
9776

9877
window.postMessage(
9978
{
@@ -116,7 +95,6 @@ function updateSnapShotTree(snap: Snapshot, mode: Mode): void {
11695
const { current } = fiberRoot;
11796
circularComponentTable.clear();
11897
snap.tree = createTree(current);
119-
12098
}
12199
sendSnapshot(snap, mode);
122100
}
@@ -212,25 +190,19 @@ function createTree(
212190
} = currentFiber;
213191

214192
if (elementType?.name && isRecoil) {
215-
console.log('Name here', elementType?.name)
216-
// console.log('Here is the state', memoizedState);
217193
let pointer = memoizedState;
218194
while (pointer !== null && pointer !== undefined && pointer.next !== null) {
219195
pointer = pointer.next;
220196
}
221-
// console.log('traverse the memoizedState 1', pointer.memoizedState);
222-
// // 2nd
223-
// console.log('traverse the memoizedState 2', pointer.memoizedState[1]?.[0]);
197+
224198
if (pointer?.memoizedState[1]?.[0].current) {
225199
const atomName = pointer.memoizedState[1]?.[0].current.keys().next().value;
226-
console.log('atom', pointer.memoizedState[1]?.[0].current.keys().next().value);
227-
allAtomsRelationship.push([atomName, elementType?.name, 1]);
200+
allAtomsRelationship.push([atomName, elementType?.name, 'atoms and components']);
228201
}
229202

230203
if (pointer?.memoizedState[1]?.[0].key) {
231204
const atomName = pointer.memoizedState[1]?.[0].key;
232-
console.log('atom', pointer.memoizedState[1]?.[0].key);
233-
allAtomsRelationship.push([atomName, elementType?.name, 1]);
205+
allAtomsRelationship.push([atomName, elementType?.name, 'atoms and components']);
234206
}
235207
}
236208

@@ -260,10 +232,7 @@ function createTree(
260232

261233
let hooksIndex;
262234

263-
// Simple check for whether our target app uses Recoil
264-
if (window[`$recoilDebugStates`]) {
265-
isRecoil = true;
266-
}
235+
267236

268237
const atomArray = [];
269238
atomArray.push(memoizedProps);

0 commit comments

Comments
 (0)