浏览代码

chore: private the root node

appflowy 2 年之前
父节点
当前提交
ac23f81e24

+ 4 - 3
shared-lib/lib-ot/src/core/document/document.rs

@@ -3,11 +3,11 @@ use crate::core::{
     DocumentOperation, NodeAttributes, NodeData, NodeSubTree, OperationTransform, TextDelta, Transaction,
 };
 use crate::errors::{ErrorBuilder, OTError, OTErrorCode};
-use indextree::{Arena, Children, FollowingSiblings, Node, NodeId};
+use indextree::{Arena, Children, FollowingSiblings, NodeId};
 
 pub struct DocumentTree {
     arena: Arena<NodeData>,
-    pub root: NodeId,
+    root: NodeId,
 }
 
 impl Default for DocumentTree {
@@ -19,6 +19,7 @@ impl Default for DocumentTree {
 impl DocumentTree {
     pub fn new() -> DocumentTree {
         let mut arena = Arena::new();
+
         let root = arena.new_node(NodeData::new("root"));
         DocumentTree { arena, root }
     }
@@ -104,7 +105,7 @@ impl DocumentTree {
     ///
     /// let inserted_note = document.node_at_path(&inserted_path).unwrap();
     /// let inserted_data = document.get_node_data(inserted_note).unwrap();
-    /// assert_eq!(inserted_data.node_type, node.node_type);
+    /// assert_eq!(inserted_data.node_type, node.note_type);
     /// ```
     pub fn child_from_node_with_index(&self, at_node: NodeId, index: usize) -> Option<NodeId> {
         let children = at_node.children(&self.arena);

+ 1 - 1
shared-lib/lib-ot/src/core/document/document_operation.rs

@@ -169,7 +169,7 @@ mod tests {
         let insert = DocumentOperation::Insert {
             path: Path(vec![0, 1]),
             nodes: vec![NodeSubTree {
-                node_type: "text".into(),
+                note_type: "text".into(),
                 attributes: NodeAttributes::new(),
                 delta: None,
                 children: vec![NodeSubTree::new("text")],

+ 6 - 3
shared-lib/lib-ot/src/core/document/node.rs

@@ -20,10 +20,13 @@ impl NodeData {
 #[derive(Clone, serde::Serialize, serde::Deserialize)]
 pub struct NodeSubTree {
     #[serde(rename = "type")]
-    pub node_type: String,
+    pub note_type: String,
+
     pub attributes: NodeAttributes,
+
     #[serde(skip_serializing_if = "Option::is_none")]
     pub delta: Option<TextDelta>,
+
     #[serde(skip_serializing_if = "Vec::is_empty")]
     pub children: Vec<NodeSubTree>,
 }
@@ -31,7 +34,7 @@ pub struct NodeSubTree {
 impl NodeSubTree {
     pub fn new(node_type: &str) -> NodeSubTree {
         NodeSubTree {
-            node_type: node_type.into(),
+            note_type: node_type.into(),
             attributes: NodeAttributes::new(),
             delta: None,
             children: Vec::new(),
@@ -40,7 +43,7 @@ impl NodeSubTree {
 
     pub fn to_node_data(&self) -> NodeData {
         NodeData {
-            node_type: self.node_type.clone(),
+            node_type: self.note_type.clone(),
             attributes: self.attributes.clone(),
             delta: self.delta.clone(),
         }

+ 1 - 1
shared-lib/lib-ot/src/core/document/transaction.rs

@@ -134,7 +134,7 @@ impl<'a> TransactionBuilder<'a> {
         });
 
         NodeSubTree {
-            node_type: node_data.node_type.clone(),
+            note_type: node_data.node_type.clone(),
             attributes: node_data.attributes.clone(),
             delta: node_data.delta.clone(),
             children,

+ 2 - 2
shared-lib/lib-ot/tests/main.rs

@@ -1,4 +1,4 @@
-use lib_ot::core::{DocumentOperation, DocumentTree, NodeAttributes, NodeSubTree, Path, TransactionBuilder};
+use lib_ot::core::{DocumentTree, NodeAttributes, NodeSubTree, Path, TransactionBuilder};
 use lib_ot::errors::OTErrorCode;
 use std::collections::HashMap;
 
@@ -70,7 +70,7 @@ fn test_inserts_subtrees() {
         tb.insert_node_at_path(
             0,
             NodeSubTree {
-                node_type: "text".into(),
+                note_type: "text".into(),
                 attributes: NodeAttributes::new(),
                 delta: None,
                 children: vec![NodeSubTree::new("image")],