Skip to content

Commit 818c972

Browse files
Added more detailed pseudocode to src/backend/tree.ts file
1 parent 568881c commit 818c972

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/backend/tree.ts

Lines changed: 23 additions & 6 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,7 +129,14 @@ 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);
@@ -152,7 +169,7 @@ class Tree {
152169
delete copy.parent;
153170
// add to circularComponentTable
154171
circularComponentTable.add(this);
155-
//
172+
//
156173
copy = scrubUnserializableMembers(copy);
157174

158175
// creates copy of each child of the present node

0 commit comments

Comments
 (0)