From e206a4145de34e795a4df2130d9059dfb4fcd9e9 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Wed, 5 Feb 2025 15:15:57 +0800 Subject: [PATCH] docs: update docs in wasm types (#634) * docs: update docs in wasm types * ci: fix test types --- crates/loro-wasm/src/lib.rs | 6 +++++- crates/loro-wasm/tests/tree.test.ts | 31 +++++++++++++++++++++-------- crates/loro/src/lib.rs | 4 ++++ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/crates/loro-wasm/src/lib.rs b/crates/loro-wasm/src/lib.rs index deb829ea..bb2db121 100644 --- a/crates/loro-wasm/src/lib.rs +++ b/crates/loro-wasm/src/lib.rs @@ -78,6 +78,10 @@ type JsResult = Result; /// [**RichText**](LoroText), [**Map**](LoroMap) and [**Movable Tree**](LoroTree), /// you could build all kind of applications by these. /// +/// **Important:** Loro is a pure library and does not handle network protocols. +/// It is the responsibility of the user to manage the storage, loading, and synchronization +/// of the bytes exported by Loro in a manner suitable for their specific environment. +/// /// @example /// ```ts /// import { LoroDoc } from "loro-crdt" @@ -6082,7 +6086,7 @@ interface LoroTree = Record> /** * Get LoroTreeNode by the TreeID. */ - getNodeByID(target: TreeID): LoroTreeNode; + getNodeByID(target: TreeID): LoroTreeNode | undefined; subscribe(listener: Listener): Subscription; toArray(): TreeNodeValue[]; getNodes(options?: { withDeleted?: boolean } ): LoroTreeNode[]; diff --git a/crates/loro-wasm/tests/tree.test.ts b/crates/loro-wasm/tests/tree.test.ts index eb577b15..87f92683 100644 --- a/crates/loro-wasm/tests/tree.test.ts +++ b/crates/loro-wasm/tests/tree.test.ts @@ -59,10 +59,10 @@ describe("loro tree", () => { it("getNodeByID", () => { const root = tree.createNode(); const child = tree.createNode(root.id); - assertEquals(tree.getNodeByID(child.id).id, child.id); + assertEquals(tree.getNodeByID(child.id)!.id, child.id); tree.delete(child.id); assertEquals(child.isDeleted(), true); - assertEquals(tree.getNodeByID(child.id).id, child.id); + assertEquals(tree.getNodeByID(child.id)!.id, child.id); }); it("parent", () => { @@ -90,7 +90,7 @@ describe("loro tree", () => { const arr = tree2.toArray(); expect(arr).toMatchSnapshot(); assertEquals(arr.length, 1); - assertEquals(arr[0].children.length, 2) + assertEquals(arr[0].children.length, 2); const keys = Object.keys(arr[0]); assert(keys.includes("id")); assert(keys.includes("parent")); @@ -107,11 +107,26 @@ describe("loro tree", () => { const child = root.createNode(); const nodes = tree2.getNodes({ withDeleted: false }); assertEquals(nodes.length, 2); - assertEquals(nodes.map((n) => { return n.id }), [root.id, child.id]) + assertEquals( + nodes.map((n) => { + return n.id; + }), + [root.id, child.id], + ); tree2.delete(child.id); const nodesWithDeleted = tree2.getNodes({ withDeleted: true }); - assertEquals(nodesWithDeleted.map((n) => { return n.id }), [root.id, child.id]); - assertEquals(tree2.getNodes({ withDeleted: false }).map((n) => { return n.id }), [root.id]); + assertEquals( + nodesWithDeleted.map((n) => { + return n.id; + }), + [root.id, child.id], + ); + assertEquals( + tree2.getNodes({ withDeleted: false }).map((n) => { + return n.id; + }), + [root.id], + ); }); it("subscribe", async () => { @@ -222,7 +237,7 @@ describe("loro tree node", () => { }); child2.move(child); loro.commit(); - unsub() + unsub(); assertEquals(child2.parent()!.id, child.id); }); @@ -251,7 +266,7 @@ describe("loro tree node", () => { assert(childrenKeys.includes("fractionalIndex")); assert(childrenKeys.includes("meta")); assert(childrenKeys.includes("children")); - }) + }); }); function one_ms(): Promise { diff --git a/crates/loro/src/lib.rs b/crates/loro/src/lib.rs index e619faf8..f9a60128 100644 --- a/crates/loro/src/lib.rs +++ b/crates/loro/src/lib.rs @@ -86,6 +86,10 @@ pub use counter::LoroCounter; /// `LoroDoc` is the entry for the whole document. /// When it's dropped, all the associated [`Handler`]s will be invalidated. +/// +/// **Important:** Loro is a pure library and does not handle network protocols. +/// It is the responsibility of the user to manage the storage, loading, and synchronization +/// of the bytes exported by Loro in a manner suitable for their specific environment. #[derive(Debug)] pub struct LoroDoc { doc: InnerLoroDoc,