Class LoroTreeNode<T>

The handler of a tree node.

Type Parameters

  • T extends Record<string, unknown> = Record<string, unknown>

Constructors

  • Type Parameters

    • T extends Record<string, unknown> = Record<string, unknown>

    Returns LoroTreeNode<T>

Properties

data: LoroMap<T>

Get the associated metadata map container of a tree node.

id: `${number}@${number}`

The TreeID of the node.

Methods

  • Returns string

  • Get the children of this node.

    The objects returned are new js objects each time because they need to cross the WASM boundary.

    Returns LoroTreeNode<T>[]

  • Create a new node as the child of the current node and return an instance of LoroTreeNode.

    If the index is not provided, the new node will be appended to the end.

    Parameters

    • Optionalindex: number

    Returns LoroTreeNode<T>

    import { LoroDoc } from "loro-crdt";

    let doc = new LoroDoc();
    let tree = doc.getTree("tree");
    let root = tree.createNode();
    let node = root.createNode();
    let node2 = root.createNode(0);
    // root
    // / \
    // node2 node
  • Get the creation id of this node.

    Returns { counter: number; peer: `${number}` }

  • Get the creator of this node.

    Returns `${number}`

  • Get the Fractional Index of the node.

    Note: the tree container must be attached to the document.

    Returns string

  • Returns void

  • Get the last mover of this node.

    Returns { counter: number; peer: `${number}` }

  • Get the index of the node in the parent's children.

    Returns number

  • Check if the node is deleted.

    Returns boolean

  • Move this tree node to be a child of the parent. If the parent is undefined, this node will be a root node.

    If the index is not provided, the node will be appended to the end.

    It's not allowed that the target is an ancestor of the parent.

    Parameters

    Returns void

    const doc = new LoroDoc();
    const tree = doc.getTree("tree");
    const root = tree.createNode();
    const node = root.createNode();
    const node2 = node.createNode();
    node2.move(undefined, 0);
    // node2 root
    // |
    // node
  • Move the tree node to be after the target node.

    Parameters

    Returns void

    import { LoroDoc } from "loro-crdt";

    const doc = new LoroDoc();
    const tree = doc.getTree("tree");
    const root = tree.createNode();
    const node = root.createNode();
    const node2 = root.createNode();
    node2.moveAfter(node);
    // root
    // / \
    // node node2
  • Move the tree node to be before the target node.

    Parameters

    Returns void

    import { LoroDoc } from "loro-crdt";

    const doc = new LoroDoc();
    const tree = doc.getTree("tree");
    const root = tree.createNode();
    const node = root.createNode();
    const node2 = root.createNode();
    node2.moveBefore(node);
    // root
    // / \
    // node2 node
  • Get the parent node of this node.

    • The parent of the root node is undefined.
    • The object returned is a new js object each time because it need to cross the WASM boundary.

    Returns LoroTreeNode<T>

  • Returns TreeNodeJSON<T>