0.4.3 • Published 4 months ago

@vulppi/node-tree v0.4.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Vulppi Tree Node

Installation

npm add @vulppi/node-tree

Methods & Properties

Properties

NameTypeDefault
idreadonly stringnone
namestringundefined
parentVulppiNodenull
prevSiblingVulppiNodenull
nextSiblingVulppiNodenull
flags{[key: string]: boolean}{}
properties{[key: string]: any}{}

Methods

NameType
destroy(): void
clone(): VulppiNode
getChildren(): VulppiNode[]
addChild(child: VulppiNode, index?: number): void
getChild(index: number \| string \| VulppiNode): VulppiNode \| null
removeChild(index: number \| VulppiNode): VulppiNode \| null
addInRoot(child: VulppiNode, index?: number): void
contains(child: VulppiNode): boolean
findIndex(child: VulppiNode): number
findChild(id: string): VulppiNode \| null
findByName(name: string): VulppiNode[]
on(event: string, cb: Function): void
off(event: string, cb: Function): Function \| null
isEmpty(): boolean
isPropsEmpty(): boolean
isFlagsEmpty(): boolean
isAllEmpty(): boolean
mergeToParent(): void
toObject(): ParsedNode
toJSON(): string
static fromObject(data: ParsedNode): VulppiNode
static fromJSON(data: string): VulppiNode

Properties Description

id

Unique identifier among its sibling nodes.

It's a required field in the node's constructor.

name

It is an optional field to find the node in the entire tree, returning a list of nodes with the same name.

parent

If the node has a parent, this property points to its parent. If not, the property is null.

nextSibling

If the node has a next sibling, this property points to its node. Otherwise the property is null.

prevSibling

If the node has a previous sibling, this property points to its node. Otherwise the property is null.

flags

This property allows receiving boolean flags.

properties

Location where our data is assigned.

This field can also be typed.

interface MyNodeProps {
  foo: string
}

const myNode = new VulppiNode<MyNodeProps>('my-id')

myNode.properties.foo = 'bar'

Methods Description

destroy

This method destroys the node and removes it from the tree.

clone

Cleanly clone the node and all of its children.

getChildren

This method brings up the list of children.

getRoot

This method brings up the root parent.

addChild

Method for adding a new child to the node's child list.

If a node with the same ID is found, it will be merged with the existing node.

There is also the possibility to add the child in a specific position.

getChild

Retrieves a child from position or an ID.

removeChild

Removes a child from its position or the child's own.

addInRoot

This method allows you to add a node to the tree's main node list.

contains

Check whether the node is contained in the tree.

findIndex

Returns our son's position if found.

findChild

Finds a child node from its ID.

findByName

Returns a list of nodes that have the same name within the tree.

on

Add an event point to the node.

off

Remove an event point to the node.

isEmpty

Check if the node has any children.

isPropsEmpty

Check if the node has any property.

isFlagsEmpty

Check if the node has any flag.

isAllEmpty

Check that the node has no children, no properties, and no flags.

mergeToParent

This method allows the node to merge with its parent.

toObject

Converts the node to a clean object.

toJSON

Converts the node into a json object in string.

static fromObject

Creates a new node from an object.

static fromJSON

Creates a new node from an JSON string.

0.4.3

4 months ago

0.4.2

6 months ago

0.4.1

12 months ago

0.4.0

1 year ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

3 years ago

0.2.1

3 years ago

0.3.2

3 years ago

0.2.3

3 years ago

0.1.4

3 years ago

0.3.1

3 years ago

0.2.2

3 years ago

0.1.5

3 years ago

0.0.1

3 years ago