Skip to content

Commit b2d1ede

Browse files
committed
added comments, console logs, and commented out code
1 parent cc982a9 commit b2d1ede

File tree

8 files changed

+104
-72
lines changed

8 files changed

+104
-72
lines changed

src/app/containers/MainContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function MainContainer(): any {
2828
useEffect(() => {
2929
// only open port once
3030
if (currentPort) return;
31-
// open connection with background script
31+
// open long-lived connection with background script
3232
const port = chrome.runtime.connect();
3333

3434
// listen for a message containing snapshots from the background script

src/backend/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ const mode: Mode = {
2626
paused: false,
2727
locked: false,
2828
};
29-
console.log("linkFiberStart in index.ts:" + linkFiberStart);
29+
// console.log("linkFiberStart in index.ts:" + linkFiberStart);
3030
const linkFiber = linkFiberStart(snapShot, mode);
31-
console.log('linkFiber in index.ts: ' + linkFiber);
31+
// console.log('linkFiber in index.ts: ' + linkFiber);
3232
const timeJump = timeJumpStart(snapShot, mode);
3333

34-
function getRouteURL(node: SnapshotNode): string {
35-
if (node.name === 'Router') {
36-
return node.state.location.pathname;
37-
}
38-
if (node.children && node.children.length >= 1) {
39-
const tempNode: any[] = node.children;
40-
for (let index = 0; index < tempNode.length; index += 1) {
41-
return getRouteURL(tempNode[index]); // Carlos: ???
42-
}
43-
}
44-
}
34+
// function getRouteURL(node: SnapshotNode): string {
35+
// if (node.name === 'Router') {
36+
// return node.state.location.pathname;
37+
// }
38+
// if (node.children && node.children.length >= 1) {
39+
// const tempNode: any[] = node.children;
40+
// for (let index = 0; index < tempNode.length; index += 1) {
41+
// return getRouteURL(tempNode[index]); // Carlos: ???
42+
// }
43+
// }
44+
// }
4545

4646
// * Event listener for time-travel actions
4747
window.addEventListener('message', ({ data: { action, payload } }: MsgData) => {
48-
console.log('linkFiber in index.ts: ' + linkFiber);
48+
// console.log('linkFiber in index.ts: ' + linkFiber);
4949
switch (action) {
5050
case 'jumpToSnap':
5151
timeJump(payload, true); // * This sets state with given payload
@@ -94,5 +94,5 @@ window.addEventListener('message', ({ data: { action, payload } }: MsgData) => {
9494
break;
9595
}
9696
});
97-
97+
// connect to dev tools and new fiber
9898
linkFiber();

src/backend/linkFiber.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ let rtid = null;
4141
let recoilDomNode = {};
4242

4343
// Simple check for whether our target app uses Recoil
44+
// can these be regular
4445
if (window[`$recoilDebugStates`]) {
4546
isRecoil = true;
4647
}
@@ -102,8 +103,8 @@ function sendSnapshot(snap: Snapshot, mode: Mode): void {
102103
function updateSnapShotTree(snap: Snapshot, mode: Mode): void {
103104
// this is the currently active root fiber(the mutable root of the tree)
104105
let fiberRootCurrent = fiberRoot.current;
105-
console.log("fiber root props: ", Object.entries(fiberRootCurrent));
106-
console.log("fiberroot sibling:", fiberRootCurrent.sibling, "fiberroot stateNode:", fiberRootCurrent.stateNode, "fiberroot child:", fiberRootCurrent.child, "fiberroot memoizedState:", fiberRootCurrent.memoizedState, "fiberroot memoizedProps:", fiberRootCurrent.memoizedProps, "fiberRootCurrent.elementType:",fiberRootCurrent.elementType, "fiberRootCurrent.tag: ", fiberRootCurrent.tag, "fiberRootCurrent.actualDuration: ", fiberRootCurrent.actualDuration, "fiberRootCurrent.actualStartTime: ", fiberRootCurrent.actualStartTime, "fiberRootCurrent.selfBaseDuration: ", fiberRootCurrent.selfBaseDuration, "fiberRootCurrent.treeBaseDuration:", fiberRootCurrent.treeBaseDuration);
106+
// console.log("fiber root props: ", Object.entries(fiberRootCurrent));
107+
// console.log("fiberroot sibling:", fiberRootCurrent.sibling, "fiberroot stateNode:", fiberRootCurrent.stateNode, "fiberroot child:", fiberRootCurrent.child, "fiberroot memoizedState:", fiberRootCurrent.memoizedState, "fiberroot memoizedProps:", fiberRootCurrent.memoizedProps, "fiberRootCurrent.elementType:",fiberRootCurrent.elementType, "fiberRootCurrent.tag: ", fiberRootCurrent.tag, "fiberRootCurrent.actualDuration: ", fiberRootCurrent.actualDuration, "fiberRootCurrent.actualStartTime: ", fiberRootCurrent.actualStartTime, "fiberRootCurrent.selfBaseDuration: ", fiberRootCurrent.selfBaseDuration, "fiberRootCurrent.treeBaseDuration:", fiberRootCurrent.treeBaseDuration);
107108

108109
if (fiberRoot) {
109110
const { current } = fiberRoot;
@@ -269,7 +270,7 @@ function createTree(
269270
} = {};
270271
let componentFound = false;
271272

272-
// Check if node is a stateful setState component
273+
// Check if node is a stateful class component
273274
if (stateNode && stateNode.state && (tag === 0 || tag === 1 || tag === 2)) {
274275
// Save component's state and setState() function to our record for future
275276
// time-travel state changing. Add record index to snapshot so we can retrieve.
@@ -344,6 +345,7 @@ function createTree(
344345
} else if (newState) {
345346
newState.hooksState = [{ [hooksNames[i]]: state.state }];
346347
} else {
348+
// possibly app breaks somewhere if newState and hooksState do not exist?
347349
newState = { hooksState: [] };
348350
newState.hooksState.push({ [hooksNames[i]]: state.state });
349351
}
@@ -370,6 +372,7 @@ function createTree(
370372

371373
// We want to add this fiber node to the snapshot
372374
if (componentFound || newState === 'stateless') {
375+
// where does this get changed to true?
373376
if (fromSibling) {
374377

375378
if(isRecoil){
@@ -397,7 +400,7 @@ function createTree(
397400
}
398401
rtidCounter++;
399402
}
400-
403+
// tree object from tree.ts, with addSibling
401404
newNode = tree.addSibling(
402405
newState,
403406
elementType ? elementType.name : 'nameless',
@@ -477,15 +480,17 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
477480
const devTools = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
478481
const reactInstance = devTools ? devTools.renderers.get(1) : null;
479482
fiberRoot = devTools.getFiberRoots(1).values().next().value;
480-
console.log("fiberRoot in export default: " + Object.entries(fiberRoot));
483+
// console.log("fiberRoot in export default: " + Object.entries(fiberRoot));
481484
const throttledUpdateSnapshot = throttle(() => updateSnapShotTree(snap, mode), 70);
482485
document.addEventListener('visibilitychange', onVisibilityChange);
483486

484487
if (reactInstance && reactInstance.version) {
488+
// when is this being called...
485489
devTools.onCommitFiberRoot = (function (original) {
486490
return function (...args) {
487491
console.log("args in onCommitFiberRoot: ", args)
488492
// eslint-disable-next-line prefer-destructuring
493+
489494
fiberRoot = args[1];
490495
if (doWork) {
491496
throttledUpdateSnapshot();

src/backend/masterState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// import {Hook}
88
import {
99
// eslint-disable-next-line @typescript-eslint/no-unused-vars
10-
HookStateItem,
11-
HookStates,
10+
HookStateItem, // obj with state and component
11+
HookStates, // array of hook state items
1212
} from './types/backendTypes';
1313

1414
const componentActionsRecord: HookStates = [];

src/backend/timeJump.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,34 @@ export default (origin, mode) => {
2626
// Set the state of the origin tree if the component is stateful
2727
function jump(target, firstCall = false) {
2828
if (!target) return;
29-
29+
//console.log("target in jump: ", target)
3030
if (target.state === 'stateless') {
3131
target.children.forEach(child => jump(child));
3232
return;
3333
}
34+
//
3435
const component = componentActionsRecord.getComponentByIndex(
3536
target.componentData.index,
3637
);
38+
// console.log("component in time jump: ", component)
39+
// check if it is a stateful class component
40+
// if yes, find the component by its index and assign it to a variable
41+
// call that components setState method to reset state to the state at the time of the jump snapshot
42+
// if (target.state && !target.state.hooksState)
3743
if (component && component.setState) {
3844
component.setState(
3945
prevState => {
46+
// console.log("prevState: ", prevState);
4047
Object.keys(prevState).forEach(key => {
41-
if (target.state[key] === undefined) {
48+
// console.log("target state object at key: ", target.state[key])
49+
// what is this edge case??
50+
if (!target.state[key] === undefined) {
4251
target.state[key] = undefined;
4352
}
53+
// does this do the same?
54+
// if (!target.state[key]) {
55+
// target.state[key];
56+
// }
4457
});
4558
return target.state;
4659
},
@@ -52,10 +65,13 @@ export default (origin, mode) => {
5265
// Check for hooks state and set it with dispatch()
5366
if (target.state && target.state.hooksState) {
5467
target.state.hooksState.forEach(hook => {
68+
// console.log("hook: ", hook);
5569
const hooksComponent = componentActionsRecord.getComponentByIndex(
5670
target.componentData.hooksIndex,
5771
);
72+
// console.log("hooksComponent: ", hooksComponent);
5873
const hookState = Object.values(hook);
74+
// console.log("hookstate in hooks if block: ", hookState);
5975
if (hooksComponent && hooksComponent.dispatch) {
6076
hooksComponent.dispatch(hookState[0]);
6177
}

src/backend/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Tree {
6464
}
6565

6666
addChild(state: string | {}, name: string, componentData: {}, rtid: any, recoilDomNode:any): Tree {
67-
console.log("arguments in addChild: "+ arguments.length)
67+
//console.log("arguments in addChild: "+ arguments.length)
6868
const newChild: Tree = new Tree(state, name, componentData, rtid, recoilDomNode);
6969
newChild.parent = this;
7070
this.children.push(newChild);

src/extension/background.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
// import 'core-js';
2-
/* eslint-disable max-len */
3-
/* eslint-disable no-param-reassign */
4-
/* eslint-disable function-paren-newline */
5-
/* eslint-disable implicit-arrow-linebreak */
6-
7-
import snapshots from "../app/components/snapshots";
8-
1+
// import snapshots from "../app/components/snapshots";
2+
import 'core-js';
93
// store ports in an array
104
const portsArr = [];
115
const reloaded = {};
126
const firstSnapshotReceived = {};
137
// there will be the same number of objects in here as there are reactime tabs open for each user application being worked on
148
const tabsObj = {};
15-
9+
console.log("hello from background")
1610
function createTabObj(title) {
1711
// update tabsObj
1812
return {
@@ -25,7 +19,7 @@ function createTabObj(title) {
2519
index: 0,
2620
//* this is our pointer so we know what the current state the user is checking (this accounts for time travel aka when user clicks jump on the UI)
2721
currLocation: null,
28-
// points the node that will generate the next child set by newest node or jump
22+
// points to the node that will generate the next child set by newest node or jump
2923
currParent: 0,
3024
// points to the current branch
3125
currBranch: 0,
@@ -44,14 +38,9 @@ function createTabObj(title) {
4438

4539
class Node {
4640
constructor(obj, tabObj) {
47-
// eslint-disable-next-line no-param-reassign
48-
// eslint-disable-next-line no-multi-assign
49-
// eslint-disable-next-line no-plusplus
5041
// continues the order of number of total state changes
51-
// eslint-disable-next-line no-plusplus
5242
this.index = tabObj.index++;
5343
// continues the order of number of states changed from that parent
54-
// eslint-disable-next-line no-multi-assign
5544
this.name = tabObj.currParent += 1;
5645
// marks from what branch this node is originated
5746
this.branch = tabObj.currBranch;
@@ -76,9 +65,9 @@ function sendToHierarchy(tabObj, newNode) {
7665
tabObj.currLocation = newNode;
7766
}
7867
}
79-
68+
// used for map visualization
8069
function changeCurrLocation(tabObj, rootNode, index, name) {
81-
// index comes from the app's main reducer to locate the right current location on tabObj
70+
// index comes from the app's main reducer to locate the correct current location on tabObj
8271
// check if current node has the index wanted
8372
if (rootNode.index === index) {
8473
tabObj.currLocation = rootNode;
@@ -99,7 +88,7 @@ function changeCurrLocation(tabObj, rootNode, index, name) {
9988
}
10089
}
10190

102-
// establishing connection with devtools
91+
// establishing incoming connection with devtools
10392
chrome.runtime.onConnect.addListener((port) => {
10493
// port is one end of the connection - an object
10594

@@ -124,7 +113,7 @@ chrome.runtime.onConnect.addListener((port) => {
124113
}
125114
});
126115

127-
// receive snapshot from devtools and send it to contentScript -
116+
// listen for message containing a snapshot from devtools and send it to contentScript -
128117
port.onMessage.addListener((msg) => {
129118
// msg is action denoting a time jump in devtools
130119

@@ -182,13 +171,13 @@ chrome.runtime.onConnect.addListener((port) => {
182171
break;
183172
default:
184173
}
185-
174+
// one time request sent to content s
186175
chrome.tabs.sendMessage(tabId, msg);
187176
return true; // attempt to fix message port closing error, consider return Promise
188177
});
189178
});
190179

191-
// background.js recieves message from contentScript.js
180+
// background.js listening for a message from contentScript.js
192181
chrome.runtime.onMessage.addListener((request, sender) => {
193182
// IGNORE THE AUTOMATIC MESSAGE SENT BY CHROME WHEN CONTENT SCRIPT IS FIRST LOADED
194183
if (request.type === 'SIGN_CONNECT') {
@@ -199,7 +188,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
199188
const { action, index, name } = request;
200189
let isReactTimeTravel = false;
201190

202-
// Filter out tabs that don't have reactime
191+
// Filter out tabs that don't have reactime, tabs that dont use react?
203192
if (
204193
action === 'tabReload' ||
205194
action === 'recordSnap' ||
@@ -251,6 +240,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
251240
// resets hierarchy to page initial state recorded when emptied
252241
tabsObj[tabId].hierarchy = tabsObj[tabId].initialHierarchy;
253242
} else {
243+
// triggered with new tab opened
254244
// resets snapshots to page initial state
255245
tabsObj[tabId].snapshots.splice(1);
256246
// checks if hierarchy before reset
@@ -346,6 +336,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
346336

347337
// when tab is closed, remove the tabid from the tabsObj
348338
chrome.tabs.onRemoved.addListener((tabId) => {
339+
console.log('tab is deleted.')
349340
// tell devtools which tab to delete
350341
if (portsArr.length > 0) {
351342
portsArr.forEach((bg) =>
@@ -364,6 +355,7 @@ chrome.tabs.onRemoved.addListener((tabId) => {
364355

365356
// when a new url is loaded on the same tab, this remove the tabid from the tabsObj, recreate the tab and inject the script
366357
chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
358+
console.log("new site loaded.")
367359
// check if the tab title changed to see if tab need to restart
368360
if (changeInfo && tabsObj[tabId]) {
369361
if (changeInfo.title && changeInfo.title !== tabsObj[tabId].title) {
@@ -388,8 +380,9 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
388380
}
389381
});
390382

391-
// when tab is view change, put the tabid as the current tab
383+
// when tab view is changed, put the tabid as the current tab
392384
chrome.tabs.onActivated.addListener((info) => {
385+
console.log("tab view has changed")
393386
// tell devtools which tab to be the current
394387
if (portsArr.length > 0) {
395388
portsArr.forEach((bg) =>
@@ -414,6 +407,7 @@ chrome.runtime.onInstalled.addListener(() => {
414407
// when context menu is clicked, listen for the menuItemId,
415408
// if user clicked on reactime, open the devtools window
416409
chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
410+
console.log('inspect clicked reactime')
417411
const options = {
418412
type: 'panel',
419413
left: 0,

0 commit comments

Comments
 (0)