From fb028f861df239b3ca64e0641542f7ac937a873f Mon Sep 17 00:00:00 2001 From: Leon Zhao Date: Thu, 20 Jun 2024 16:52:36 +0800 Subject: [PATCH] fix: export CommitOptions & JsonSchema (#389) --- crates/loro-internal/src/handler/tree.rs | 9 ++++----- crates/loro-wasm/src/lib.rs | 2 +- crates/loro/src/lib.rs | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/loro-internal/src/handler/tree.rs b/crates/loro-internal/src/handler/tree.rs index 853ba90a..b520c8f0 100644 --- a/crates/loro-internal/src/handler/tree.rs +++ b/crates/loro-internal/src/handler/tree.rs @@ -615,17 +615,16 @@ impl TreeHandler { } // TODO: iterator - pub fn children(&self, parent: Option) -> Vec { + pub fn children(&self, parent: Option) -> Option> { match &self.inner { MaybeDetached::Detached(t) => { let t = t.try_lock().unwrap(); - t.value.get_children(parent).unwrap() + t.value.get_children(parent) } MaybeDetached::Attached(a) => a.with_state(|state| { let a = state.as_tree_state().unwrap(); a.get_children(&TreeParentId::from(parent)) - .unwrap() - .collect() + .map(|x| x.collect()) }), } } @@ -696,7 +695,7 @@ impl TreeHandler { } pub fn roots(&self) -> Vec { - self.children(None) + self.children(None).unwrap_or_default() } #[allow(non_snake_case)] diff --git a/crates/loro-wasm/src/lib.rs b/crates/loro-wasm/src/lib.rs index 5fb09f6f..972d19bd 100644 --- a/crates/loro-wasm/src/lib.rs +++ b/crates/loro-wasm/src/lib.rs @@ -2939,7 +2939,7 @@ impl LoroTreeNode { /// the WASM boundary. #[wasm_bindgen(skip_typescript)] pub fn children(&self) -> Array { - let children = self.tree.children(Some(self.id)); + let children = self.tree.children(Some(self.id)).unwrap_or_default(); let children = children.into_iter().map(|c| { let node = LoroTreeNode::from_tree(c, self.tree.clone(), self.doc.clone()); JsValue::from(node) diff --git a/crates/loro/src/lib.rs b/crates/loro/src/lib.rs index 34796674..f89c0ca1 100644 --- a/crates/loro/src/lib.rs +++ b/crates/loro/src/lib.rs @@ -11,9 +11,7 @@ use loro_internal::cursor::Side; use loro_internal::encoding::ImportBlobMetadata; use loro_internal::handler::HandlerTrait; use loro_internal::handler::ValueOrHandler; -use loro_internal::loro::CommitOptions; use loro_internal::undo::{OnPop, OnPush}; -use loro_internal::JsonSchema; use loro_internal::LoroDoc as InnerLoroDoc; use loro_internal::OpLog; @@ -40,10 +38,12 @@ pub use loro_internal::delta::{TreeDeltaItem, TreeDiff, TreeExternalDiff}; pub use loro_internal::event::Index; pub use loro_internal::handler::TextDelta; pub use loro_internal::id::{PeerID, TreeID, ID}; +pub use loro_internal::loro::CommitOptions; pub use loro_internal::obs::SubID; pub use loro_internal::oplog::FrontiersNotIncluded; pub use loro_internal::undo; pub use loro_internal::version::{Frontiers, VersionVector}; +pub use loro_internal::JsonSchema; pub use loro_internal::UndoManager as InnerUndoManager; pub use loro_internal::{loro_value, to_value}; pub use loro_internal::{LoroError, LoroResult, LoroValue, ToJson}; @@ -1368,7 +1368,7 @@ impl LoroTree { } /// Return all children of the target node. - pub fn children(&self, parent: Option) -> Vec { + pub fn children(&self, parent: Option) -> Option> { self.handler.children(parent) }