mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-05 12:14:43 +00:00
docs: update docs in wasm types (#634)
* docs: update docs in wasm types * ci: fix test types
This commit is contained in:
parent
8fdb25e8c3
commit
e206a4145d
3 changed files with 32 additions and 9 deletions
|
@ -78,6 +78,10 @@ type JsResult<T> = Result<T, JsValue>;
|
|||
/// [**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<T extends Record<string, unknown> = Record<string, unknown>>
|
|||
/**
|
||||
* Get LoroTreeNode by the TreeID.
|
||||
*/
|
||||
getNodeByID(target: TreeID): LoroTreeNode<T>;
|
||||
getNodeByID(target: TreeID): LoroTreeNode<T> | undefined;
|
||||
subscribe(listener: Listener): Subscription;
|
||||
toArray(): TreeNodeValue[];
|
||||
getNodes(options?: { withDeleted?: boolean } ): LoroTreeNode<T>[];
|
||||
|
|
|
@ -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<void> {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue