Class: NodeObject

qi-nodes. NodeObject


new NodeObject( [parent])

These objects, or types of them, are used in composite patterns.
Each instance of module:qi-nodes.NodeObject is aware of
it's own position within a tree of objects. If any tree has a root,
that root is propagated to all leaves of that tree.
When a leaf is removed from a rooted tree, the previous root
reference is removed for all objects contained in that leaf.

Parameters:
Name Type Argument Description
parent Object <optional>

Optional parent object to append this object to

Members


childCount :Object

Number of children in this object.

Type:
  • Object

firstChild :Object

Reference to the first child object of this object.
Should never be falsey if this object has 1 or more children.

Type:
  • Object

lastChild :Object

Reference to the last child object of this object.
Should never be falsey if this object has 1 or more children.

Type:
  • Object

nextSibling :Object

Reference to the next object relative to this object
within the list of child objects of its parent.
Should always be falsey if this object has no parent.
If this object has a parent and this value is falsey,
then this object is the last child of its parent.

Type:
  • Object

parent :Object

Reference to this object's parent object.
Should never be falsey if this object is a child to another object.

Type:
  • Object

previousSibling :Object

Reference to the previous object relative to this object
within the list of child objects of its parent.
If this object has a parent and this value is falsey,
then this object is the first child of its parent.

Type:
  • Object

root :Object

When an object is rooted, this property is a reference to itself.
This is a unique property that is propagated through the leaves
of an object tree, but only from an object with its root set
to a truthy value.

Type:
  • Object

Methods


append(node [, parent])

Add the specified object as the module:qi-nodes.NodeObject#lastChild of the parent object.
An object cannot be added to itself.

Parameters:
Name Type Argument Description
node Object

The object to add to this object

parent Object <optional>

The object to add the object to, defaults to this object

Throws:
Returns:

The object added

Type
Object

appendTo(parent [, node])

Add the object as the module:qi-nodes.NodeObject#lastChild of the specified parent object.
An object cannot be added to itself.

Parameters:
Name Type Argument Description
parent Object

The object to add the object to

node Object <optional>

The object to add, defaults to this object

Throws:
Returns:

The object added

Type
Object

create( [parent])

Factory method that creates objects from this.constructor.prototype.

Parameters:
Name Type Argument Description
parent Object <optional>

Optional parent object to append this object to

Returns:

Instance of this.constructor.prototype optionally added to parent

Type
*

createRoot()

Helper factory method that creates a new rooted object.
This means that it's root property is a reference to itself.

Returns:

created rooted object

Type
module:qi-nodes.NodeObject

destroy( [recursive] [, node])

module:qi-nodes.NodeObject#empty the object's children,
and module:qi-nodes.NodeObject#remove it from its parent.
This essentially sets all properties to null that make this object a node.

Parameters:
Name Type Argument Description
recursive boolean <optional>

If true, will recursively empty all children, defaults to false

node Object <optional>

The object to destroy, defaults to this object

Returns:

The object destroyed

Type
Object

eachChildFrom(fn [, node] [, thisObject])

Recursively iterate over each object down through all it's leaves.

Parameters:
Name Type Argument Description
fn function

The function to invoke for each object iterated

node Object <optional>

The starting object, defaults to this object

thisObject Object <optional>

Callback function context, defaults to node

Returns:

The starting object

Type
Object

eachChildTo(fn [, node] [, thisObject])

Recursively iterate over each object up through all it's leaves.

Parameters:
Name Type Argument Description
fn function

The function to invoke for each object iterated

node Object <optional>

The starting object, defaults to this object

thisObject Object <optional>

Callback function context, defaults to node

Returns:

The starting object

Type
Object

eachParentFrom(fn [, node] [, thisObject])

Recursively iterate over each object up through all it's parents.

Parameters:
Name Type Argument Description
fn function

The function to invoke for each object iterated

node Object <optional>

The starting object, defaults to this object

thisObject Object <optional>

Callback function context, defaults to node

Returns:

The starting object

Type
Object

eachParentTo(fn [, node] [, thisObject])

Recursively iterate over each object down through all it's parents.

Parameters:
Name Type Argument Description
fn function

The function to invoke for each object iterated

node Object <optional>

The starting object, defaults to this object

thisObject Object <optional>

Callback function context, defaults to node

Returns:

The starting object

Type
Object

empty( [recursive] [, node])

Remove all the object's children, but leaves its module:qi-nodes.NodeObject#parent intact.

Parameters:
Name Type Argument Description
recursive boolean <optional>

If true, will recursively empty all children, defaults to false

node Object <optional>

The object to empty, defaults to this object

Returns:

The object emptied

Type
Object

insertAfter(sibling [, node])

Add the object as the module:qi-nodes.NodeObject#nextSibling of the specified sibling object.
The sibling specified must be a child of a parent object.
An object cannot be added to itself.

Parameters:
Name Type Argument Description
sibling Object

The object to insert the object after

node Object <optional>

The object to add, defaults to this object

Throws:
Returns:

The object added

Type
Object

insertBefore(sibling [, node])

Add the object as the module:qi-nodes.NodeObject#previousSibling of the specified sibling object.
The sibling specified must be a child of a parent object.
An object cannot be added to itself.

Parameters:
Name Type Argument Description
sibling Object

The object to insert the object before

node Object <optional>

The object to add, defaults to this object

Throws:
Returns:

The object added

Type
Object

prepend(node [, parent])

Add the specified object as the module:qi-nodes.NodeObject#firstChild of the parent object.
An object cannot be added to itself.

Parameters:
Name Type Argument Description
node Object

The object to add to this object

parent Object <optional>

The object to add the object to, defaults to this object

Throws:
Returns:

The object added

Type
Object

prependTo(parent [, node])

Add the object as the module:qi-nodes.NodeObject#firstChild of the specified parent object.
An object cannot be added to itself.

Parameters:
Name Type Argument Description
parent Object

The object to add the object to

node Object <optional>

The object to add, defaults to this object

Throws:
Returns:

The object added

Type
Object

remove( [child])

Remove the child object from its module:qi-nodes.NodeObject#parent, but leaves its children intact.

Parameters:
Name Type Argument Description
child Object <optional>

The object to remove, defaults to this object

Returns:

The object removed

Type
Object

swap(node1 [, node2])

Swap one object's position with another object's.

Parameters:
Name Type Argument Description
node1 Object

The object to swap with node2

node2 Object <optional>

The object to swap with node1, defaults to this object

Returns:

node1 object

Type
Object