Skip to content

Commit b0f237e

Browse files
authored
Merge pull request #25 from hienqn/implementAtomsMap
Parsed through the fiber tree to get atoms and components data to render onto the front end, added new feature to select what to render
2 parents 63a7e04 + 94e1118 commit b0f237e

File tree

4 files changed

+67
-53
lines changed

4 files changed

+67
-53
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
@@ -120,6 +120,7 @@
120120
"react-dom": "^16.13.1",
121121
"react-google-chart": "^0.1.2",
122122
"react-google-charts": "^3.0.15",
123+
"react-google-charts-ts": "^0.1.1",
123124
"react-html-parser": "^2.0.2",
124125
"react-json-tree": "^0.11.2",
125126
"react-router-dom": "^5.2.0",

src/app/components/AtomsRelationship.jsx

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,53 @@
1-
import React, { Component, useEffect, useState } from 'react';
1+
import React, { Component, useEffect, useState, Fragment } from 'react';
22
// import * as d3 from 'd3';
33
// import {sankey} from 'sankey';
4-
import { Chart } from 'react-google-charts';
4+
import { Chart } from 'react-google-charts'
5+
6+
// import { Fragment } from '../../backend/types/backendTypes';
57

68
/**
79
* @method maked3Tree :Creates a new D3 Tree
810
*/
911

1012
function AtomsRelationship(props) {
11-
console.log('Props', props.atomsRel);
1213

1314
const {atomsRel} = props
1415

1516

17+
const atomsAndComp = atomsRel.filter(e => e[2] !== 'atoms and selectors').map(e => {
18+
let copy = [...e];
19+
copy[2] = 1;
20+
return [...copy]
21+
})
22+
const atomsAndSelectors = atomsRel.filter(e => e[2] === 'atoms and selectors').map(e => {
23+
let copy = [...e];
24+
copy[2] = 1;
25+
return [...copy]
26+
})
27+
const copyatomsRel = atomsRel.map(e => { let copy = [...e]; copy[2] = 1; return copy; });
28+
29+
// console.log('atoms and selectors', atomsAndSelectors);
30+
// console.log('copy Atom rel', copyatomsRel);
31+
// console.log('initial atom rel', atomsRel);
32+
const [atoms, setAtoms] = useState([...copyatomsRel]);
33+
const [atomAndSelectorCheck, setAtomAndSelectorCheck] = useState(false);
34+
const [atomAndCompCheck, setAtomAndCompCheck] = useState(false);
35+
36+
useEffect( () => {
37+
if ((!atomAndSelectorCheck && !atomAndCompCheck) || (atomAndSelectorCheck && atomAndCompCheck)) {
38+
setAtoms(copyatomsRel);
39+
} else if (atomAndSelectorCheck) {
40+
setAtoms(atomsAndSelectors);
41+
} else {
42+
setAtoms(atomsAndComp);
43+
}
44+
}, [atomAndSelectorCheck, atomAndCompCheck, props])
45+
1646
return (
17-
<div className="history-d3-container" id="atomsContainer">
18-
{atomsRel && (
47+
<div className="history-d3-container">
48+
{atoms && (
49+
// <div>
50+
<Fragment>
1951
<Chart
2052
width={'100%'}
2153
height={'100%'}
@@ -49,9 +81,19 @@ function AtomsRelationship(props) {
4981
tooltip: { textStyle: { color: 'white', fontSize: 0.1, }},
5082
}}
5183
loader={<div>Loading Chart</div>}
52-
data={[['Atom', 'Selector', ''], ...atomsRel]}
84+
data={[['Atom', 'Selector', ''], ...atoms]}
5385
rootProps={{ 'data-testid': '1' }}
54-
/>)}
86+
/>
87+
<div>
88+
<input type="checkbox" id='atomscomps' onClick={e => setAtomAndCompCheck(atomAndCompCheck ? false: true)}/>
89+
<label htmlFor="atomscomps"> Only Show Atoms (or Selectors) and Components </label>
90+
<input type="checkbox" id='atomsselectors' onClick={e => setAtomAndSelectorCheck(atomAndSelectorCheck ? false : true)} />
91+
<label htmlFor="atomsselectors"> Only Show Atoms and Selectors </label>
92+
</div>
93+
</Fragment>
94+
)
95+
96+
}
5597
</div>
5698
);
5799
}

src/backend/linkFiber.ts

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -60,37 +60,17 @@ const circularComponentTable = new Set();
6060
let allAtomsRelationship = [];
6161

6262
function getRecoilState() : any {
63-
// get the last state snapshot
6463
const RecoilSnapshotsLength = window[`$recoilDebugStates`].length;
6564
const lastRecoilSnapshot = window[`$recoilDebugStates`][RecoilSnapshotsLength - 1];
66-
console.log(lastRecoilSnapshot);
67-
68-
// get all atom - selector pairs, and save them as nodes
69-
// in the from to weight format
7065
const nodeToNodeSubs = lastRecoilSnapshot.nodeToNodeSubscriptions;
7166
let nodeToNodeSubsKeys = lastRecoilSnapshot.nodeToNodeSubscriptions.keys();
7267
nodeToNodeSubsKeys.forEach(
7368
node => {
7469
nodeToNodeSubs.get(node).forEach(
75-
nodeSubs => allAtomsRelationship.push([node, nodeSubs, 1])
70+
nodeSubs => allAtomsRelationship.push([node, nodeSubs, 'atoms and selectors'])
7671
)
7772
}
7873
)
79-
80-
// get all atom - component pairs, and save them as nodes
81-
// in the from to weight format
82-
83-
// const nodeToCompSubs = lastRecoilSnapshot.nodeToComponentSubscriptions;
84-
// console.log(nodeToCompSubs);
85-
// let nodeToCompSubsKeys = lastRecoilSnapshot.nodeToComponentSubscriptions.keys();
86-
// nodeToCompSubsKeys.forEach(
87-
// node => {
88-
// console.log(node);
89-
// // nodeToCompSubsKeys.get(node).forEach(
90-
// // nodeSubs => allAtomsRelationship.push([node, nodeSubs, 2])
91-
// // )
92-
// }
93-
// )
9474
}
9575

9676

@@ -186,13 +166,13 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
186166
if (pointer?.memoizedState[1]?.[0].current) {
187167
let atomName = pointer.memoizedState[1]?.[0].current.keys().next().value;
188168
console.log('atom', pointer.memoizedState[1]?.[0].current.keys().next().value);
189-
allAtomsRelationship.push([atomName, elementType?.name, 1])
169+
allAtomsRelationship.push([atomName, elementType?.name, 'atoms and components'])
190170
}
191171

192172
if (pointer?.memoizedState[1]?.[0].key) {
193173
let atomName = pointer.memoizedState[1]?.[0].key;
194174
console.log('atom', pointer.memoizedState[1]?.[0].key);
195-
allAtomsRelationship.push([atomName, elementType?.name, 1])
175+
allAtomsRelationship.push([atomName, elementType?.name, 'atoms and components'])
196176
}
197177
}
198178

@@ -276,17 +256,6 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
276256
state.component
277257
);
278258
componentData.hooksIndex = hooksIndex;
279-
280-
// if (newState && newState.hooksState) {
281-
// newState.hooksState.push({ [hooksNames[i]]: state.state });
282-
// } else if (newState) {
283-
// newState.hooksState = [{ [hooksNames[i]]: state.state }];
284-
// } else {
285-
// newState = { hooksState: [] };
286-
// newState.hooksState.push({ [hooksNames[i]]: state.state });
287-
// }
288-
289-
//improves tree visualization but breaks jump
290259
if (newState && newState.hooksState) {
291260
newState.push(state.state);
292261
} else if (newState) {
@@ -399,18 +368,7 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
399368
}
400369

401370
return () => {
402-
/* const container = document.getElementById('root');
403-
if (container._internalRoot) {
404-
fiberRoot = container._internalRoot;
405-
} else {
406-
const {
407-
_reactRootContainer: { _internalRoot },
408-
_reactRootContainer,
409-
} = container;
410-
// Only assign internal root if it actually exists
411-
fiberRoot = _internalRoot || _reactRootContainer;
412-
}
413-
*/
371+
414372
const devTools = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
415373
const reactInstance = devTools ? devTools.renderers.get(1) : null;
416374
fiberRoot = devTools.getFiberRoots(1).values().next().value;

0 commit comments

Comments
 (0)