@@ -453,9 +453,9 @@ export class CRDTTreeNode extends IndexTreeNode<CRDTTreeNode> {
453
453
}
454
454
455
455
/**
456
- * toJSON converts the given CRDTNode to JSON .
456
+ * toTreeNode converts the given CRDTTreeNode to TreeNode .
457
457
*/
458
- function toJSON ( node : CRDTTreeNode ) : TreeNode {
458
+ function toTreeNode ( node : CRDTTreeNode ) : TreeNode {
459
459
if ( node . isText ) {
460
460
const currentNode = node ;
461
461
return {
@@ -466,7 +466,7 @@ function toJSON(node: CRDTTreeNode): TreeNode {
466
466
467
467
return {
468
468
type : node . type ,
469
- children : node . children . map ( toJSON ) ,
469
+ children : node . children . map ( toTreeNode ) ,
470
470
attributes : node . attrs
471
471
? parseObjectValues ( node . attrs ?. toObject ( ) )
472
472
: undefined ,
@@ -679,7 +679,7 @@ export class CRDTTree extends CRDTGCElement {
679
679
toPath : this . toPath ( toParent , toLeft ) ,
680
680
actor : editedAt . getActorID ( ) ! ,
681
681
value : contents ?. length
682
- ? contents . map ( ( content ) => toJSON ( content ) )
682
+ ? contents . map ( ( content ) => toTreeNode ( content ) )
683
683
: undefined ,
684
684
} ) ;
685
685
@@ -951,7 +951,14 @@ export class CRDTTree extends CRDTGCElement {
951
951
* `toJSON` returns the JSON encoding of this tree.
952
952
*/
953
953
public toJSON ( ) : string {
954
- return JSON . stringify ( toJSON ( this . indexTree . getRoot ( ) ) ) ;
954
+ return JSON . stringify ( this . getRootTreeNode ( ) ) ;
955
+ }
956
+
957
+ /**
958
+ * `getRootTreeNode` returns the converted value of this tree to TreeNode.
959
+ */
960
+ public getRootTreeNode ( ) : TreeNode {
961
+ return toTreeNode ( this . indexTree . getRoot ( ) ) ;
955
962
}
956
963
957
964
/**
0 commit comments