-
Notifications
You must be signed in to change notification settings - Fork 10
All Methods
I'm trying to keep all functions good-documented, but if you're here you definitely need more info about the functions with examples etc.
P.S. Don't forget to star this library. It stimulates me to support the library! ⭐️
P.P.S. If you feel like you could help me with the library (writing docs, adding new features, testing, fixing bugs or anything else) - you are welcome! If you need any info or have a question, just email me at fremail@yandex.com
Let's call the Model as
Modeland the instance of that model asrecord.
Create a root node from existing or new record.
async Model.createRoot(record, options = {}): recordGet root node for selected rootId.
async Model.fetchRoot(rootId = 1, options = {}): record|falseGet all tree nodes.
async Model.fetchTree(depth = 0, rootId = 1, options = {}): [record]|falseGet all root nodes.
async Model.fetchRoots(options = {}): [record]|falseasync record.hasPrevSibling(options = {}): boolasync record.hasNextSibling(options = {}): boolrecord.hasChildren(): boolrecord.hasParent(): boolGet previous sibling of the node.
async record.getPrevSibling(options = {}): record|falseGet next sibling of the node.
async record.getNextSibling(options = {}): record|falseGet all siblings of the node including current node or not.
async record.getSiblings(withCurrentNode = false, options = {}): [record]Get first child of the node.
async record.getFirstChild(options = {}): record|falseGet last child of the node.
async record.getLastChild(options = {}): record|falseGet all children of the node.
async record.getChildren(options = {}): [record]|falseGet all or limited by depth descendants for the node.
async record.getDescendants(depth = 0, options = {}): [record]|falseasync record.getParent(options = {}): record|falseGet all or limited by depth ancestors for the node.
async record.getAncestors(depth = 0, options = {}): [record]|falseGet number of direct children nodes (only from one next level).
async record.getNumberChildren(options = {}): numberGet number of descendants (children and their children).
record.getNumberDescendants(): numberInsert the node (from which you call the function) as parent of destination node.
async record.insertAsParentOf(destNode, options = {})Insert the node (from which you call the function) as previous sibling of destination node.
async record.insertAsPrevSiblingOf(destNode, options = {})Insert the node (from which you call the function) as next sibling of destination node.
async record.insertAsNextSiblingOf(destNode, options = {})Insert the node (from which you call the function) as first child of destination node.
async record.insertAsFirstChildOf(destNode, options = {})Insert the node (from which you call the function) as last child of destination node.
async record.insertAsLastChildOf(destNode, options = {})Move the node (from which you call the function) as previous sibling of destination node.
async record.moveAsPrevSiblingOf(destNode, options = {})Move the node (from which you call the function) as next sibling of destination node.
async record.moveAsNextSiblingOf(destNode, options = {})Move the node (from which you call the function) as first child of destination node.
async record.moveAsFirstChildOf(destNode, options = {})Move the node (from which you call the function) as last child of destination node.
async record.moveAsLastChildOf(destNode, options = {})Make this node a root node and move all its descendants to the new tree. Only for multiple-root trees.
async record.makeRoot(options = {})
// deprecated from v. 1.2.0:
async record.makeRoot(newRootId, options = {})Add the node as last child of the supplied node (new parent)
async record.addChild(parentNode, options = {})Check if the node is leaf (doesn't have children)
record.isLeaf(): boolCheck if the node is root
record.isRoot(): boolCheck if the node is equal to the supplied node
record.isEqualTo(node): boolCheck if the node is descendant of the supplied node
record.isDescendantOf(node): boolCheck if the node is descendant or sibling to supplied node
record.isDescendantOfOrEqualTo(node): boolCheck if the node is ancestor of the supplied node
record.isAncestorOf(node): boolCheck if the node is valid. It checks the supplied node, or the source node otherwise.
record.isValidNode(node = null): boolDetach the node from the tree by invalidating its left and right values.
record.detach()Delete the node with all its children.
async record.delete(options = {})