IRISGlobalNode

"intersystems-iris". IRISGlobalNode

This class provides an iterable interface that behaves like a virtual dictionary representing the immediate children of a global node. IRISGlobalNode, which behaves like a virtual dictionary representing the immediate children of a global array node.

IRISGlobalNode is iterable: IRISGlobalNode supports iterable interface using for-of loop.

  
for (let x of node) console.log(x) 

It implements the JavaScript Iterator protocol, which means it implements the [Symbol.iterator] function. This function returns an Iterator over subscript-value pairs of the node (like a call to the entries() function). This allows IRISGlobalNode to be iterated directly within a for-of loop as seen above, but one can also invoke the [Symbol.iterator] function directly to obtain an iterator.

  
const iterator = node[Symbol.iterator]()
const nextPair = iterator.next()
console.log(nextPair) 

IRISGlobalNode can be iterated in many different ways: Methods keys(), subscripts(), values(), entries(), nodes(), and nodeEntries() return iterators over different views of the IRISGlobalNode subscript-value pairs. For example, the items() method returns an iterator over the sub-nodes of the IRISGlobalNode.

 
for (let x of node.nodes()) console.log(x)

IRISGlobalNode is reversable: If the function reverse() gets called the iteration of the IRISGlobalNode will go backwards / reversed from the standard order.

For example:

 
for (let x of node.reverse().entries()) console.log(x)

will traverse the subscripts from last (inclusive) to first (exclusive).

Finally, IRISGlobalNode supports membership tests (has), and allows setting or getting subscript-value pairs

Constructor

# new IRISGlobalNode(iris, globalName, …subscripts)

Parameters:
Name Type Attributes Description
iris module:"intersystems-iris".Iris

the iris instance to use to communicate with the IRIS server

globalName string

the name of the global node

subscripts any <repeatable>
Properties
Name Type Description
size number

The number of subscript-value pairs in the IRISGlobalNode

Methods

# clear()

Completely deletes the IRISGlobalNode from the IRIS server

Returns:

undefined

# delete(subscript)

Removes the specified value from the IRISGlobalNode object by subscript

Parameters:
Name Type Description
subscript *

the subscript to be removed

Returns:

true if the subscript existed and has been removed, or false if the subscript does not exist

# entries()

Returns an Iterator object of the current IRISGlobalNode which can be iterated over to yield subscript-value pairs. Iterator is an iterable so the for-of loop can be used.

Tutorials:
Returns:

a new Iterator object of the current IRISGlobalNode

Example
// can be used directly in a for loop because the Iterator class is iterable
 for (let x of node.entries()) console.log(x)

# forEach(callback, thisArg)

Executes a provided function once per each subscript/value pair in the IRISGlobalNode

Parameters:
Name Type Description
callback callback

Function to execute for each subscript/value pair in the IRISGlobalNode

thisArg any

value to use as this when executing the callback

# get(subscript, default_value)

Returns a specified value from an IRISGlobalNode object.

Parameters:
Name Type Description
subscript *

the subscript to return from the IRISGlobalNode

default_value any

a value to return if the subscript does not exist

Returns:

the value associated with the specified subscript or undefined (or default_value)
if the node is UNDEFINED

# has(subscript)

Returns a boolean indicating whether a value with the specified subscript exists or not.

Note: searches the immediate sub-nodes of the node, not deeper level subscripts!

Parameters:
Name Type Description
subscript *

the subscript to look for

Returns:

true if a value for the specified subscript exist in the IRISGlobalNode; otherwise false

# keys()

Returns an Iterator object of the current IRISGlobalNode which can be iterated over to yield only subscripts. Iterator is an iterable so the for-of loop can be used.

Tutorials:
Returns:

a new Iterator object of the current IRISGlobalNode

Example
// can be used directly in a for loop because the Iterator class is iterable
 for (let x of node.keys()) console.log(x)

# node(subscript)

Returns an IRISGlobalNode object that represents the subnode at a given subscript

Parameters:
Name Type Description
subscript *

the subscript of the requested subnode

Returns:

a new IRISGlobalNode object

# nodeEntries()

Returns an Iterator object of the current IRISGlobalNode which can be iterated over to yield subscript-subnode pairs. Iterator is an iterable so the for-of loop can be used.

Tutorials:
Returns:

a new Iterator object of the current IRISGlobalNode

Example
// can be used directly in a for loop because the Iterator class is iterable
 for (let x of node.nodeEntries()) console.log(x)

# nodes()

Returns an Iterator object of the current IRISGlobalNode which can be iterated over to yield only subnodes. Iterator is an iterable so the for-of loop can be used.

Tutorials:
Returns:

a new Iterator object of the current IRISGlobalNode

Example
// can be used directly in a for loop because the Iterator class is iterable
 for (let x of node.nodes()) console.log(x)

# reversed()

Returns a reverse Iterator object of the current IRISGlobalNode which can be iterated over to yield subscript-value pairs. Iterator is an iterable so the for-of loop can be used. When the protocol [Symbol.iterator] is used, it returns a function that, when invoked, returns this iterator itself

Tutorials:
Returns:

a new Iterator object of the current IRISGlobalNode

Example
// can be used directly in a for loop because the Iterator class is iterable
 for (let x of node.reversed()) console.log(x)

# set(subscript, value)

Adds or updates the value of a specified subscript in the IRISGlobalNode

Parameters:
Name Type Description
subscript *

the subscript of the value to add in the IRISGlobalNode

value any

the value to add in the IRISGlobalNode

Returns:

the IRISGlobalNode object

# subscripts()

Alias for keys()

Tutorials:
Returns:

a new Iterator object of the current IRISGlobalNode

Example
// can be used directly in a for loop because the Iterator class is iterable
 for (let x of node.keys()) console.log(x)