6
6
/* eslint-disable no-console */
7
7
/* eslint-disable no-param-reassign */
8
8
9
- // ~~ I dont like the fact that these are global variables ~~ - Zack
10
9
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
12
11
let componentNames = { } ; // {componentName: frequency of use} => component name as a key and it's frequency of use as its value
13
12
14
13
// Functions dont serialize properly so we need to scrub for that
@@ -19,12 +18,13 @@ function scrubUnserializableMembers(tree: Tree): Tree {
19
18
return tree ;
20
19
}
21
20
22
- // Making a deep clone of an object
21
+ // Making a deep clone of state becuase we want to make a copy
23
22
function serializeState ( state ) {
24
23
try {
25
24
// makes a deep clone, but this way can be very slow
26
25
return JSON . parse ( JSON . stringify ( state ) ) ;
27
26
} catch ( e ) {
27
+ // if there is an error, that means there is circular state i.e state that depends on itself
28
28
return 'circularState' ;
29
29
}
30
30
}
@@ -37,6 +37,9 @@ function serializeState(state) {
37
37
* @param componentData - {props: {}} - Data in the component tree
38
38
* @param chilren - {(Tree | string)[]} - An array of children nodes
39
39
* @param parent - {Tree} - the parent node
40
+ * @param isExpanded - {boolean}
41
+ * @param rtid - {any}
42
+ * @param route -
40
43
* @parent generates a new tree (recursive call)
41
44
*/
42
45
class Tree {
@@ -106,7 +109,14 @@ class Tree {
106
109
// return name
107
110
return name ;
108
111
}
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
+ */
110
120
addChild ( state : string | { } , name : string , componentData : { } , rtid : any ) : Tree {
111
121
// gets unique name by calling checkForDuplicates method
112
122
const uniqueName = this . checkForDuplicates ( name ) ;
@@ -119,7 +129,14 @@ class Tree {
119
129
// return newChild
120
130
return newChild ;
121
131
}
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
+ */
123
140
addSibling ( state : string | { } , name : string , componentData : { } , rtid : any ) : Tree {
124
141
// gets unique name by calling checkForDuplicates method
125
142
const uniqueName = this . checkForDuplicates ( name ) ;
@@ -152,7 +169,7 @@ class Tree {
152
169
delete copy . parent ;
153
170
// add to circularComponentTable
154
171
circularComponentTable . add ( this ) ;
155
- //
172
+ //
156
173
copy = scrubUnserializableMembers ( copy ) ;
157
174
158
175
// creates copy of each child of the present node
0 commit comments