Skip to content

Commit da3c6d0

Browse files
committed
merge with dev branch
2 parents d9c63b7 + 41e15be commit da3c6d0

File tree

2 files changed

+55
-28
lines changed

2 files changed

+55
-28
lines changed

src/backend/tree.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
/* eslint-disable no-console */
77
/* eslint-disable no-param-reassign */
88

9-
// ~~ I dont like the fact that these are global variables ~~ - Zack
109
let copyInstances = 0; // Tells you if we have already made a copy of current tree??
11-
const circularComponentTable = new Set<Tree>(); // Keeps track of the nodes added to the tree
10+
const circularComponentTable = new Set<Tree>(); // Keeps track of the nodes added to the tree and allows you make sure there isnt circular state
1211
let componentNames = {}; // {componentName: frequency of use} => component name as a key and it's frequency of use as its value
1312

1413
// Functions dont serialize properly so we need to scrub for that
@@ -19,12 +18,13 @@ function scrubUnserializableMembers(tree: Tree): Tree {
1918
return tree;
2019
}
2120

22-
// Making a deep clone of an object
21+
// Making a deep clone of state becuase we want to make a copy
2322
function serializeState(state) {
2423
try {
2524
// makes a deep clone, but this way can be very slow
2625
return JSON.parse(JSON.stringify(state));
2726
} catch (e) {
27+
// if there is an error, that means there is circular state i.e state that depends on itself
2828
return 'circularState';
2929
}
3030
}
@@ -37,6 +37,9 @@ function serializeState(state) {
3737
* @param componentData - {props: {}} - Data in the component tree
3838
* @param chilren - {(Tree | string)[]} - An array of children nodes
3939
* @param parent - {Tree} - the parent node
40+
* @param isExpanded - {boolean}
41+
* @param rtid - {any}
42+
* @param route -
4043
* @parent generates a new tree (recursive call)
4144
*/
4245
class Tree {
@@ -106,7 +109,14 @@ class Tree {
106109
// return name
107110
return name;
108111
}
109-
112+
/**
113+
*
114+
* @param state - string if root, serialized state otherwise
115+
* @param name - name of child
116+
* @param componentData - props
117+
* @param rtid - ??
118+
* @returns - return new tree instance that is child
119+
*/
110120
addChild(state: string | {}, name: string, componentData: {}, rtid: any): Tree {
111121
// gets unique name by calling checkForDuplicates method
112122
const uniqueName = this.checkForDuplicates(name);
@@ -119,13 +129,20 @@ class Tree {
119129
// return newChild
120130
return newChild;
121131
}
122-
132+
/**
133+
*
134+
* @param state - string if root, serialized state otherwise
135+
* @param name - name of child
136+
* @param componentData - props
137+
* @param rtid - ??
138+
* @returns - return new tree instance that is child
139+
*/
123140
addSibling(state: string | {}, name: string, componentData: {}, rtid: any): Tree {
124141
// gets unique name by calling checkForDuplicates method
125142
const uniqueName = this.checkForDuplicates(name);
126143
// instantiate new sibilng tree with state, uniqueName, componentName and rtid
127144
const newSibling: Tree = new Tree(state, uniqueName, componentData, rtid);
128-
// updating newSibling parent to be the parent of "this" which refers to sibling node
145+
// updating newSibling's parent to be the parent of "this" which refers to sibling node
129146
newSibling.parent = this.parent;
130147
// adds newSibling to children array
131148
this.parent.children.push(newSibling);
@@ -143,27 +160,31 @@ class Tree {
143160
*/
144161
// if we havent made a copy of the tree, increment copyInstances and clear cicularComponentTable set
145162
if (copyInstances === 0) {
163+
// increment copyInstances
146164
copyInstances++;
165+
// clear circularComponentTable
147166
circularComponentTable.clear();
148167
}
149168
// creates copy of present node
150169
let copy: Tree = new Tree(this.state, this.name, this.componentData, this.rtid);
151-
// you want to get rid of the parentNode?? not sure why
170+
// you want to get rid of the parentNode becuase right now copy and "this" have the same parent and you dont want that
152171
delete copy.parent;
153172
// add to circularComponentTable
154173
circularComponentTable.add(this);
155-
//
174+
// remove unserializable Trees
156175
copy = scrubUnserializableMembers(copy);
157176

158-
// creates copy of each child of the present node
177+
// creates copy of each child of the present node and assigns it to children property of the new copy Tree
159178
copy.children = this.children.map((child: Tree): Tree | string => {
179+
// if child isnt in circularComponent table, return recursive call of cleanTreeCopy() on child. We need to do this to fully build out the tree
160180
if (!circularComponentTable.has(child)) {
161181
return child.cleanTreeCopy();
162182
}
163183
return 'circular';
164184
});
165-
185+
// reset copyInstances back to zero becuase we are done making a copy of the tree
166186
copyInstances--;
187+
// return the copy
167188
return copy;
168189
}
169190
}

src/backend/types/backendTypes.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,31 @@
44
import Tree from '../tree';
55

66
/**
7-
* The snapshot of the current tree
8-
* @param tree - {Tree} - The tree structure to send to front end
9-
* @param unfilteredTree - {null} - The current mode (i.e. jumping, time-traveling, or paused)
7+
* @type Tree - The snapshot of the current tree
8+
* @member tree - {Tree} - The tree structure to send to front end
9+
* @member unfilteredTree - {null} - The current mode (i.e. jumping, time-traveling, or paused)
1010
*/
1111
export interface Snapshot {
1212
tree: Tree;
1313
unfilteredTree: null;
1414
}
1515

1616
/**
17-
* Where we
18-
* @param jumping - whether we are jumping steps by
19-
* @param paused - true/false for whether pausing to see the state
17+
* @type Mode - object that describes where we are
18+
* @member jumping - whether we are jumping steps by
19+
* @member paused - true/false for whether pausing to see the state
2020
*/
2121
export interface Mode {
2222
jumping: boolean;
2323
paused: boolean;
2424
}
2525

2626
/**
27-
*
27+
* This is what is shown in developer tools??
28+
* @type SnapshotNode
29+
* @member name -
30+
* @member state -
31+
* @member children -
2832
*/
2933
export interface SnapshotNode {
3034
name: string;
@@ -34,7 +38,8 @@ export interface SnapshotNode {
3438
children: any[];
3539
}
3640
/**
37-
* @param data - an object with action & payload properties
41+
* @type MsgData - obj with data object that will be sent to window?
42+
* @member data - an object with action & payload properties
3843
*/
3944
export interface MsgData {
4045
data: {
@@ -44,14 +49,14 @@ export interface MsgData {
4449
}
4550

4651
/**
47-
*
48-
* @param index -
49-
* @param hooksIndex -
50-
* @param actualDuration -
51-
* @param actualStartTime -
52-
* @param selfBaseDuration -
53-
* @param treeBaseDuration -
54-
* @param props -
52+
* @type ComponentData -
53+
* @member index -
54+
* @member hooksIndex -
55+
* @member actualDuration -
56+
* @member actualStartTime -
57+
* @member selfBaseDuration -
58+
* @member treeBaseDuration -
59+
* @member props -
5560
*/
5661
export interface ComponentData {
5762
index?: number;
@@ -64,8 +69,9 @@ export interface ComponentData {
6469
}
6570

6671
/**
67-
* @param state -
68-
* @param component -
72+
* @type HookStateItem
73+
* @member state -
74+
* @member component -
6975
*/
7076
export interface HookStateItem {
7177
state: any;

0 commit comments

Comments
 (0)