Skip to content

Commit b59b22f

Browse files
committed
working on helper function to connect incoming state snapshots with d3 visualization
1 parent 6d7f2b8 commit b59b22f

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

package/tree.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable no-console */
22
/* eslint-disable no-param-reassign */
3+
4+
// this is the current snapshot that is being sent to the snapshots array. it is an object
35
class Tree {
46
constructor(component, useStateInstead = false, name) {
57
// special case when component is root

src/extension/background.js

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,68 @@
22
const portsArr = [];
33
const reloaded = {};
44
const firstSnapshotReceived = {};
5+
// there will be the same number of objects in here as there are reactime tabs open for each user application being worked on
56
const tabsObj = {};
67

78
function createTabObj(title) {
9+
// updating tabsObj
810
return {
911
title,
12+
// snapshots is an array of ALL state snapshots for the reactime tab working on a specific user application
1013
snapshots: [],
11-
//* inserting a new property
12-
snapshotHierarchy: {},
14+
//* 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)
15+
currentStatePointer: null,
16+
//* inserting a new property to build out our hierarchy dataset for d3
17+
hierarchy: null,
1318
mode: {
1419
persist: false,
1520
locked: false,
1621
paused: false,
1722
},
1823
};
1924
}
25+
// once state is modified (when user does something with app), a step appears in actionContainer.jsx column. That current state snapshot is added to our hierarchy object. That is what the buildHierarchy function is for. It takes in the entire tabObj, which has a hierarcy object as a property within it. Then we build this hierarchy object so that d3 can render graphs in our extension
26+
function buildHierarchy(obj, newNode) {
27+
// whenever we receive a snapshot from contentScript.js via message, we execute this function
28+
//* if empty on extension UI is clicked hierarchy needs to be reset to an object
29+
let num = 1;
30+
class d3Node {
31+
constructor(num, obj) {
32+
this.name = num++;
33+
this.stateSnapshot = obj;
34+
this.children = [];
35+
}
36+
}
37+
38+
obj.hierarchy
39+
/* properties inside this object absolutely requires:
40+
name: string (the first state snapshot has to be a root)
41+
stateSnapshot: object
42+
currentStateSnapshot: boolean
43+
*/
44+
45+
// each time a statesnapshot is added, this gets incremented otherwise it will be decremented
46+
// we need to find a way to traverse through the object to know which node the user is on so we can add a new state snapshot in the right location
47+
// could we potentially have a variable in timejump function (timeJump.js in the package) that our function can work with --> contentScript.js has access to it --> we can access that variable message;
48+
stateCount = 1;
49+
50+
class stateNode {
51+
52+
constructor() {
53+
this.name = `state${stateCount}`;
54+
this.stateSnapshot = {};
55+
this.children = [];
56+
}
57+
}
2058

21-
function buildHierarchy() {
22-
// if empty is clicked hierarchy needs to be reset to an object
23-
24-
// once state is modified (when user does something with app), a step appears in actionContainer.jsx column
25-
// that current state snapshot is added to our hierarchy object
2659

27-
}
28-
// create a helper function that groups all the snapshots underneath each other
60+
// create a helper function that groups all the snapshots underneath each other
2961
// current state snapshot
30-
// needs to be supplied by the UI
31-
// also need to figure out how we would traverse through the big ass object to find the current state
62+
// needs to be supplied by the UI
63+
// also need to figure out how we would traverse through the big ass object to find the current state
3264
// Create a new object with name,
65+
}
66+
3367

3468
// establishing connection with devtools
3569
chrome.runtime.onConnect.addListener(port => {
@@ -137,6 +171,9 @@ chrome.runtime.onMessage.addListener((request, sender) => {
137171
reloaded[tabId] = false;
138172

139173
tabsObj[tabId].snapshots.push(request.payload);
174+
//! INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN!!!!
175+
let currentStateObject = tabsObj[tabId]
176+
buildHierarchy(tabsObj[tabId], request.payloadTurnedIntoNODE );
140177
console.log(tabsObj[tabId].snapshots);
141178
if (portsArr.length > 0) {
142179
portsArr.forEach(bg => bg.postMessage({
@@ -150,8 +187,11 @@ chrome.runtime.onMessage.addListener((request, sender) => {
150187
// don't add anything to snapshot storage if tab is reloaded for the initial snapshot
151188
if (reloaded[tabId]) {
152189
reloaded[tabId] = false;
153-
} else tabsObj[tabId].snapshots.push(request.payload);
154-
190+
} else {
191+
tabsObj[tabId].snapshots.push(request.payload);
192+
//! INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN!!!!
193+
buildHierarchy();
194+
}
155195
// send message to devtools
156196
if (portsArr.length > 0) {
157197
portsArr.forEach(bg => bg.postMessage({

0 commit comments

Comments
 (0)