NodeApi

Interface to node objects. The current node object is accessed from js.node

js.node.children

Type
array.<NodeApi>

Array of child nodes once children have been rendered

js.node.dom

Type
Element

DOM element of this node’s rendered HTML

js.node.id

Type
string

ID of this node, also given to id of HTML div tag wrapping this node

js.node.parent

Type
NodeApi

parent of this node, null for root node

js.node.title

Type
string

Title of this node, set from node property

js.node.call(method, params) ⇒ promise

ParamTypeDescription
methodstring

method name to call on referenced module

params*

parameters for the method

Only works on ReferenceNodes. Initiate an async call to the module behind the refnode. The method being called needs to be bound first on the receiving module using js.module.bind(). Returns a Promise which will be resolved with the method’s return value.

js.node.evaluateLogic() ⇒ boolean

Run the logic script on this node. Used when implementing a custom renderChildren function, to conditionally render child nodes. Returns true or false, the result of this node’s logic script.

js.node.ready(callback)

ParamDescription
callback

function to call when node has been rendered.

Accepts a function that will get called when all descendants of this node have been rendered. The function context this will be set to this node.

js.node.render() ⇒ NodeApi

Method to render DOM of this node. Should only be called within the renderChildren function. See renderChildren for example usage.

js.node.renderChildren(children)

Override this method to customize how children are rendered.

ParamTypeDescription
childrenNodeApi

array of child nodes

This method is passed an array of child nodes which may be rendered, the resulting child dom appended to this.dom. The array of rendered children must be returned or else the children of the rendered children will not be rendered. This is the default function to use if not overridden:

renderChildren(children){
  var rendered_children = []
  for (let child of children) {
    if(!child.evaluateLogic()) continue;
    rendered_children.push(child.render())
  }
  for (let child of rendered_children) {
    this.dom.appendChild(child.dom)
  }
  return rendered_children
}

See also: