Skip to content

Commit 16d8288

Browse files
VNguyenCodeSanjayLavingiaAlexanderLanderos
committed
(add) Successfully pass down recoilDomNode array into the props from our backend to the frontend, which will be used for our onMouseEnter event in our onHover feature in ComponentData
Co-authored-by: Sanjay Lavingia <[email protected]> Co-authored-by: Alexander Landeros <[email protected]>
1 parent 08fa38d commit 16d8288

File tree

6 files changed

+35
-20
lines changed

6 files changed

+35
-20
lines changed

src/app/components/ComponentMap.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default function ComponentMap({
3535
// preparing the data to be used for render
3636
const lastNode = snapshots.length - 1;
3737
const data = snapshots[lastNode];
38+
3839
const [layout, setLayout] = useState<string>('cartesian');
3940
const [orientation, setOrientation] = useState<string>('horizontal');
4041
const [linkType, setLinkType] = useState<string>('diagonal');
@@ -129,7 +130,7 @@ export default function ComponentMap({
129130
fill="url('#links-gradient')"
130131
onClick={() => {
131132
node.data.isExpanded = !node.data.isExpanded;
132-
console.log(node);
133+
console.log('node',node);
133134
forceUpdate();
134135
}}
135136
/>
@@ -151,7 +152,7 @@ export default function ComponentMap({
151152
console.log(node);
152153
forceUpdate();
153154
}}
154-
onMouseEnter={()=>dispatch(onHover(node.data.rtid))}
155+
onMouseEnter={()=> {dispatch(onHover(node.data.rtid))}
155156
/>
156157
)}
157158
<text

src/app/components/StateRoute.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const StateRoute = (props: StateRouteProps) => {
5555

5656
// Map
5757
const renderComponentMap = () => {
58+
5859
if (hierarchy) {
5960
return (
6061
<ParentSize>

src/backend/linkFiber.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let allAtomsRelationship = [];
3838
let initialstart = false;
3939
let rtidCounter = 0;
4040
let rtid = null;
41-
let recoilStateNode = {};
41+
let recoilDomNode = {};
4242

4343
// Simple check for whether our target app uses Recoil
4444
if (window[`$recoilDebugStates`]) {
@@ -80,9 +80,9 @@ function sendSnapshot(snap: Snapshot, mode: Mode): void {
8080
// getRecoilState();
8181
payload.atomsComponents = atomsComponents;
8282
payload.atomSelectors = atomsSelectors;
83+
payload.recoilDomNode = recoilDomNode
8384
}
8485

85-
console.log(recoilStateNode)
8686
window.postMessage(
8787
{
8888
action: 'recordSnap',
@@ -382,50 +382,56 @@ function createTree(
382382

383383
if(isRecoil){
384384
if(currentFiber.elementType.name){
385-
if(!recoilStateNode[currentFiber.elementType.name]){
386-
recoilStateNode[currentFiber.elementType.name] = [];
385+
if(!recoilDomNode[currentFiber.elementType.name]){
386+
recoilDomNode[currentFiber.elementType.name] = [];
387387
}
388388
}
389+
389390
let pointer = currentFiber
391+
390392
while(pointer !== null){
391393
if(pointer.stateNode !== null){
392394
rtid = "fromLinkFiber" + rtidCounter++
393-
recoilStateNode[currentFiber.elementType.name].push(pointer.stateNode)
395+
recoilDomNode[currentFiber.elementType.name].push(rtid)
394396
pointer.stateNode.setAttribute("id", rtid)
395397
}
396398

397399
pointer = pointer.child
398400
}
399401
}
402+
400403
newNode = tree.addSibling(
401404
newState,
402405
elementType ? elementType.name : 'nameless',
403406
componentData,
404-
rtid
407+
rtid,
408+
recoilDomNode
405409
);
406410
} else {
407411

408412
if(isRecoil){
409413
if(currentFiber.elementType.name){
410-
if(!recoilStateNode[currentFiber.elementType.name]){
411-
recoilStateNode[currentFiber.elementType.name] = [];
414+
if(!recoilDomNode[currentFiber.elementType.name]){
415+
recoilDomNode[currentFiber.elementType.name] = [];
412416
}
413417
}
414418
let pointer = currentFiber
415419
while(pointer !== null){
416420
if(pointer.stateNode !== null){
417421
rtid = "fromLinkFiber" + rtidCounter++
418-
recoilStateNode[currentFiber.elementType.name].push(pointer.stateNode)
422+
recoilDomNode[currentFiber.elementType.name].push(rtid)
419423
pointer.stateNode.setAttribute("id", rtid)
420424
}
421425
pointer = pointer.child
422426
}
423427
}
428+
424429
newNode = tree.addChild(
425430
newState,
426431
elementType ? elementType.name : 'nameless',
427432
componentData,
428-
rtid
433+
rtid,
434+
recoilDomNode
429435
);
430436
}
431437
} else {

src/backend/tree.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,27 @@ class Tree {
5151

5252
rtid: any;
5353

54-
constructor(state: string | {}, name = 'nameless', componentData: {} = {}, rtid: any = null) {
54+
recoilDomNode: any;
55+
56+
constructor(state: string | {}, name = 'nameless', componentData: {} = {}, rtid: any = null, recoilDomNode:any = null) {
5557
this.state = state === 'root' ? 'root' : serializeState(state);
5658
this.name = name;
5759
this.componentData = componentData ? JSON.parse(JSON.stringify(componentData)) : {};
5860
this.children = [];
5961
this.parent = null; // ref to parent so we can add siblings
6062
this.rtid = rtid
63+
this.recoilDomNode = recoilDomNode
6164
}
6265

63-
addChild(state: string | {}, name: string, componentData: {}, rtid: any): Tree {
64-
const newChild: Tree = new Tree(state, name, componentData, rtid);
66+
addChild(state: string | {}, name: string, componentData: {}, rtid: any, recoilDomNode:any): Tree {
67+
const newChild: Tree = new Tree(state, name, componentData, rtid, recoilDomNode);
6568
newChild.parent = this;
6669
this.children.push(newChild);
6770
return newChild;
6871
}
6972

70-
addSibling(state: string | {}, name: string, componentData: {}, rtid: any): Tree {
71-
const newSibling: Tree = new Tree(state, name, componentData, rtid);
73+
addSibling(state: string | {}, name: string, componentData: {}, rtid: any, recoilDomNode:any): Tree {
74+
const newSibling: Tree = new Tree(state, name, componentData, rtid,recoilDomNode);
7275
newSibling.parent = this.parent;
7376
this.parent.children.push(newSibling);
7477
return newSibling;
@@ -87,7 +90,7 @@ class Tree {
8790
circularComponentTable.clear();
8891
}
8992
// creates copy of present node
90-
let copy: Tree = new Tree(this.state, this.name, this.componentData, this.rtid);
93+
let copy: Tree = new Tree(this.state, this.name, this.componentData, this.rtid, this.recoilDomNode);
9194
delete copy.parent;
9295
circularComponentTable.add(this);
9396
copy = scrubUnserializableMembers(copy);

src/extension/background.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/* eslint-disable function-paren-newline */
55
/* eslint-disable implicit-arrow-linebreak */
66

7+
import snapshots from "../app/components/snapshots";
8+
79
// store ports in an array
810
const portsArr = [];
911
const reloaded = {};
@@ -282,9 +284,12 @@ chrome.runtime.onMessage.addListener((request, sender) => {
282284
break;
283285
}
284286
case 'recordSnap': {
287+
285288
const sourceTab = tabId;
286289
// first snapshot received from tab
287290
if (!firstSnapshotReceived[tabId]) {
291+
292+
288293
firstSnapshotReceived[tabId] = true;
289294
reloaded[tabId] = false;
290295

@@ -336,7 +341,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
336341
default:
337342
break;
338343
}
339-
console.log('inside background.js, tabsObj:', tabsObj);
344+
// console.log('inside background.js, tabsObj:', tabsObj);
340345
return true; // attempt to fix close port error
341346
});
342347

src/extension/contentScript.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ window.addEventListener('message', msg => { // runs automatically every second
1515

1616
// post initial Message to background.js
1717
const { action }: { action: string } = msg.data;
18-
1918
if (action === 'recordSnap') { // this is firing on page load
2019
chrome.runtime.sendMessage(msg.data);
2120
}

0 commit comments

Comments
 (0)