DescendantIndexManager

How to get DescendantIndexManager

ES2015+:

import DescendantIndexManager from 'fontoxml-dom-descendant-index/descendantIndexManager'

ES5:

define([
	'fontoxml-dom-descendant-index/descendantIndexManager'
], function (
	DescendantIndexManager
) {
});

Type: Class

Provides a way to retrieve a list of all descendants of a node matching a given selector.

Methods

Name Description
addDescendantsChangedCallback

Add a callback for changes of descendants of the container matching the itemSelector.

Use DescendantIndexManager#getIndexedDescendants to obtain the indexed nodes when the callback is invoked.

This method is optimized for descendant queries. Accessing nodes outside the subtree specified by containerNode is not supported and may yield unexpected results. For more general XPath expressions, consider using IndexManager#observeQueryResults instead.


  Arguments
# Name Type Description
1. containerNode Node

The id of the container to index the container for.

2. itemSelector XPathTest

XPath test expression determining the nodes to be returned

3. callBack Function

the callback which will be executed when the items change.

4. [options] Object

Extra options to further define when to call the callback.

  Members

Members

Name Type Description
attributes Boolean

If true, the callback will also be called when any matched node's attributes change.


  Default value
false
characterData Boolean

If true, the callback will also be called when any matched node's character data changes.


  Default value
false
  Returns

Type: Function

Removal function of the callback

getIndexedDescendants

Returns an array of descendants of the given node matching the selector.

This list of nodes is sorted by the order in the DOM. It is also not recursive, meaning that descendants of nodes matching the selector will not be indexed. If you need to index these nodes, use getIndexedDescendants recursively.

Calling this will start monitoring the results for changes. Use DescendantIndexManager#addDescendantsChangedCallback to be notified when the results change.

This method is optimized for descendant queries. Accessing nodes outside the subtree specified by containerNode is not supported and may yield unexpected results. For more general XPath expressions, consider using IndexManager#observeQueryResults instead.


  Arguments
# Name Type Description
1. containerNode Node

The node under which to run the query

2. itemSelector XPathTest

XPath test expression determining the nodes to be returned

  Returns

Type: Array<Node>

The descendants of the containerNode matching the itemSelector