@@ -142,7 +142,7 @@ class Tree {
142
142
const uniqueName = this . checkForDuplicates ( name ) ;
143
143
// instantiate new sibilng tree with state, uniqueName, componentName and rtid
144
144
const newSibling : Tree = new Tree ( state , uniqueName , componentData , rtid ) ;
145
- // 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
146
146
newSibling . parent = this . parent ;
147
147
// adds newSibling to children array
148
148
this . parent . children . push ( newSibling ) ;
@@ -160,27 +160,31 @@ class Tree {
160
160
*/
161
161
// if we havent made a copy of the tree, increment copyInstances and clear cicularComponentTable set
162
162
if ( copyInstances === 0 ) {
163
+ // increment copyInstances
163
164
copyInstances ++ ;
165
+ // clear circularComponentTable
164
166
circularComponentTable . clear ( ) ;
165
167
}
166
168
// creates copy of present node
167
169
let copy : Tree = new Tree ( this . state , this . name , this . componentData , this . rtid ) ;
168
- // 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
169
171
delete copy . parent ;
170
172
// add to circularComponentTable
171
173
circularComponentTable . add ( this ) ;
172
- //
174
+ // remove unserializable Trees
173
175
copy = scrubUnserializableMembers ( copy ) ;
174
176
175
- // 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
176
178
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
177
180
if ( ! circularComponentTable . has ( child ) ) {
178
181
return child . cleanTreeCopy ( ) ;
179
182
}
180
183
return 'circular' ;
181
184
} ) ;
182
-
185
+ // reset copyInstances back to zero becuase we are done making a copy of the tree
183
186
copyInstances -- ;
187
+ // return the copy
184
188
return copy ;
185
189
}
186
190
}
0 commit comments