Skip to content

Commit 101d3c4

Browse files
Webmetrics pretty much done. Has one error. Working on History.tsx
1 parent 336d5f7 commit 101d3c4

File tree

6 files changed

+58
-26
lines changed

6 files changed

+58
-26
lines changed

src/app/components/Diff.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { DiffProps, StatelessCleaning } from '../FrontendTypes';
1414
function Diff(props: DiffProps): JSX.Element {
1515
const {
1616
snapshot, // snapshot from 'tabs[currentTab]' object in 'MainContainer'
17-
show // boolean that is dependent on the 'Route' path
17+
show // boolean that is dependent on the 'Route' path; true if 'Route' path === '/diffRaw'
1818
} = props;
1919
const [mainState] = useStoreContext(); // useStoreContext() returns our global state object (which was initialized as 'initialState' in 'App.tsx')
2020
const { currentTab, tabs } = mainState; // 'currentTab' (type: number) and 'tabs' (type: object) are destructured from 'mainState'
@@ -60,7 +60,7 @@ function Diff(props: DiffProps): JSX.Element {
6060

6161
if (newObj.children) { // if our new object has a children property
6262
newObj.children = [];
63-
if (obj.children.length > 0) { // and if our input object's children property is non-empty, go through each children object and determine objects that need to be cleaned through statelessCleaning. Those that are cleaned through this process are then pushed to the new object's children array.
63+
if (obj.children.length > 0) { // and if our input object's children property is non-empty, go through each children object from our input object and determine, if the object being iterated on either has a stateless state or has a children array with a non-zero amount of objects. Objects that fulfill the above that need to be cleaned through statelessCleaning. Those that are cleaned through this process are then pushed to the new object's children array.
6464
obj.children.forEach(
6565
(element: { state?: Record<string, unknown> | string; children?: [] }) => {
6666
if (element.state !== 'stateless' || element.children.length > 0) {
@@ -74,18 +74,16 @@ function Diff(props: DiffProps): JSX.Element {
7474
return newObj; // return the cleaned state snapshot(s)
7575
};
7676

77-
const previousDisplay: StatelessCleaning = statelessCleaning(previous); // displays stateful data
77+
const previousDisplay: StatelessCleaning = statelessCleaning(previous); // displays stateful data from the first snapshot that was taken before our current snapshot.
7878

79-
// diff function returns a comparison of two objects, one has an updated change
80-
// just displays stateful data
81-
const delta: StatelessCleaning = diff(previousDisplay, snapshot);
79+
const delta: StatelessCleaning = diff(previousDisplay, snapshot); // diff function from 'jsondiffpatch' returns the difference in state between 'previousDisplay' and 'snapshot'
8280

83-
// returns html in string
84-
// just displays stateful data
85-
const html: StatelessCleaning = formatters.html.format(delta, previousDisplay);
86-
if (show) formatters.html.showUnchanged();
87-
else formatters.html.hideUnchanged();
88-
if (previous === undefined || delta === undefined) {
81+
const html: StatelessCleaning = formatters.html.format(delta, previousDisplay); // formatters function from 'jsondiffpatch' returns an html string that shows the difference between delta and the previousDisplay
82+
83+
if (show) formatters.html.showUnchanged(); // shows unchanged values if we're on the '/diffRaw' path
84+
else formatters.html.hideUnchanged(); // hides unchanged values
85+
86+
if (previous === undefined || delta === undefined) { // if there has been no state changes on the target/hooked application, previous and delta would be undefined.
8987
return (
9088
<div className='no-data-message'>
9189
{' '}
@@ -94,7 +92,7 @@ function Diff(props: DiffProps): JSX.Element {
9492
</div>
9593
);
9694
}
97-
return <div>{ReactHtmlParser(html)}</div>;
95+
return <div>{ReactHtmlParser(html)}</div>; // ReactHTMLParser from 'react-html-parser' package converts the HTML string into a react component.
9896
}
9997

10098
export default Diff;

src/app/components/StateRoute/History.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { DefaultMargin } from '../../FrontendTypes';
99
import { changeView, changeSlider, setCurrentTabInApp } from '../../actions/actions';
1010
import { useStoreContext } from '../../store';
1111

12+
/*
13+
Render's history page after history button has been selected. Allows user to traverse state history and relevant state branches.
14+
*/
15+
1216
const defaultMargin: DefaultMargin = {
1317
top: 30,
1418
left: 30,
@@ -28,10 +32,10 @@ function History(props: Record<string, unknown>): JSX.Element {
2832
currLocation, // from 'tabs[currentTab]' object in 'MainContainer'
2933
snapshots, // from 'tabs[currentTab].snapshotDisplay' object in 'MainContainer'
3034
} = props;
31-
const [, dispatch] = useStoreContext();
35+
const [, dispatch] = useStoreContext(); // use the dispatch that is connected with our storeContext
3236

3337
const svgRef = React.useRef(null);
34-
const root = JSON.parse(JSON.stringify(hierarchy));
38+
const root = JSON.parse(JSON.stringify(hierarchy)); // why do we stringify and then parse our hierarchy back to JSON? (asked 7/31/23)
3539

3640
// setting the margins for the Map to render in the tab window.
3741
const innerWidth: number = totalWidth - margin.left - margin.right;
@@ -128,6 +132,7 @@ function History(props: Record<string, unknown>): JSX.Element {
128132
/**
129133
* @method makeD3Tree :Creates a new D3 Tree
130134
*/
135+
131136
const makeD3Tree = () => {
132137
const svg = d3.select(svgRef.current);
133138
svg.selectAll('*').remove(); // Clear svg content before adding new elements

src/app/components/WebMetrics.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import { OptionsCursorTrueWithMargin } from '../FrontendTypes';
55
import { setCurrentTabInApp } from '../actions/actions';
66
import { useStoreContext } from '../store';
77

8+
/*
9+
Used to render a single radial graph on the 'Web Metrics' tab
10+
*/
11+
812
const radialGraph = (props) => {
913
const state = {
10-
series: [props.series],
14+
series: [props.series], // series appears to be the scale at which data is displayed based on the type of webMetrics measured.
1115
options: {
12-
colors: [props.color],
16+
colors: [props.color], // color of the webmetrics performance bar from 'StateRoute'
1317
chart: {
1418
height: 100,
1519
width: 100,
@@ -88,8 +92,8 @@ const radialGraph = (props) => {
8892
},
8993
};
9094

91-
const [store, dispatch] = useStoreContext();
92-
useEffect(() => {
95+
const [store, dispatch] = useStoreContext(); // used to get the dispatch function from our storeContext
96+
useEffect(() => { // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'webmetrics.' to facilitate render.
9397
dispatch(setCurrentTabInApp('webmetrics'));
9498
}, []);
9599

@@ -100,8 +104,8 @@ const radialGraph = (props) => {
100104
};
101105

102106
return (
103-
<div className='metric'>
104-
<ReactHover options={optionsCursorTrueWithMargin}>
107+
<div className='metric'>
108+
<ReactHover options={optionsCursorTrueWithMargin}>
105109
<Trigger type='trigger'>
106110
<div id='chart'>
107111
<Charts
@@ -114,10 +118,9 @@ const radialGraph = (props) => {
114118
</div>
115119
</Trigger>
116120
<Hover type='hover'>
117-
<div style={{ zIndex: 1, position: 'relative', padding: '0.5rem 1rem' }} id='hover-box'>
118-
<p>
119-
<strong>{props.name}</strong>
120-
</p>
121+
<div style={{zIndex: 1, position: 'relative', padding: '0.5rem 1rem'}} id='hover-box'>
122+
{/* <div style="zIndex: 1; position: relative; padding: 0.5rem 1rem;" id='hover-box'> */}
123+
<p><strong>{props.name}</strong></p>
121124
<p>{props.description}</p>
122125
</div>
123126
</Hover>

src/backend/controllers/timeJump.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,17 @@ async function updateReactFiberTree(
9494
const functionalComponent = componentActionsRecord.getComponentByIndexHooks(hooksIndex);
9595
// Update component state
9696
for (let i in functionalComponent) {
97-
await functionalComponent[i].dispatch(Object.values(hooksState)[i]);
97+
try {
98+
await functionalComponent[i].dispatch(Object.values(hooksState)[i])
99+
} catch(err) {
100+
console.log('error in timeJump')
101+
console.log('hooksIndex', hooksIndex)
102+
console.log('hookState', hooksState)
103+
console.log('[i]', i)
104+
console.log('functionalComponent', functionalComponent)
105+
console.log('functionalComponent[i]', functionalComponent[i])
106+
console.log(err)
107+
}
98108
}
99109
// Iterate through new children after state has been set
100110
targetSnapshot.children.forEach((child) => updateReactFiberTree(child));

src/extension/background.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ chrome.runtime.onConnect.addListener((port) => {
187187
break;
188188
}
189189
}
190+
return true // added 7/30/23
190191
});
191192

192193
// listen for message containing a snapshot from devtools and send it to contentScript -
@@ -409,6 +410,7 @@ chrome.tabs.onRemoved.addListener((tabId) => {
409410
delete tabsObj[tabId];
410411
delete reloaded[tabId];
411412
delete firstSnapshotReceived[tabId];
413+
return true; // added 7/30/23
412414
});
413415

414416
// when a new url is loaded on the same tab,
@@ -436,6 +438,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
436438
tabsObj[tabId] = createTabObj(changeInfo.title);
437439
}
438440
}
441+
return true; // added 7/30/23
439442
});
440443

441444
// when tab view is changed, put the tabid as the current tab
@@ -455,6 +458,7 @@ chrome.tabs.onActivated.addListener((info) => {
455458
}
456459
}
457460
});
461+
return true; // added 7/30/23
458462
});
459463

460464
// when reactime is installed
@@ -465,6 +469,7 @@ chrome.runtime.onInstalled.addListener(() => {
465469
title: 'Reactime',
466470
contexts: ['page', 'selection', 'image', 'link'],
467471
});
472+
return true; // added 7/30/23
468473
});
469474

470475
// when context menu is clicked, listen for the menuItemId,
@@ -479,4 +484,5 @@ chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
479484
url: chrome.runtime.getURL('panel.html'),
480485
};
481486
if (menuItemId === 'reactime') chrome.windows.create(options);
487+
return true; // added 7/30/23
482488
});

src/extension/contentScript.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ let firstMessage = true;
1010
// Listens for window messages (from the injected script on the DOM)
1111
let isRecording = true;
1212

13+
//event listener testing
14+
window.addEventListener("unhandledrejection", (event) => {
15+
console.log('window event listener')
16+
console.log('Promise error from message received from contentScript')
17+
console.log('promise', event.promise)
18+
console.log('reason', event.reason)
19+
})
20+
1321
window.addEventListener('message', (msg) => {
1422
// Event listener runs constantly based on actions
1523
// recorded on the test application from backend files (linkFiber.ts).
@@ -35,6 +43,8 @@ window.addEventListener('message', (msg) => {
3543
if (action === 'aReactApp') {
3644
chrome.runtime.sendMessage(msg.data);
3745
}
46+
47+
return true // newest return true to determine if this solves current unhandled exceptions.
3848
});
3949

4050
// Listening for messages from the UI of the Reactime extension.

0 commit comments

Comments
 (0)