IndexManager

How to get IndexManager

ES2015+:

import IndexManager from 'fontoxml-indices/indexManager'

ES5:

define([
	'fontoxml-indices/indexManager'
], function (
	IndexManager
) {
});

Type: Class

Provides a way to continuously run XPath queries on the loaded documents in an efficient way.

Methods

Name Description
observeQueryResults

Add a query for which results should be observed, the result of which may be a boolean, a string or a number of nodes. Observed queries will signal possible changes to the results. When the notifier triggers, the results of the query may have changed. Note that re-evaluating the query when the notifier is triggered may yield the same result as before. It may happen that the query has been evaluated differently to yield the same result. However, the results are guaranteed not to have changed if the notifier is not triggered.

Note that the notifier will not be triggered before the first call to getResults.

For the more specific problem of returning descendants of a node matching a selector, consider using the methods on DescendantIndexManager, which provide increased performance by imposing some restrictions on the query.

Example

define([
    'fontoxml-indices/indexManager'
], function (
    indexManager
) {
    'use strict';
    …
    var observer = indexManager.observeQueryResults(
        '//fn => count()',
        documentNode,
        { expectedResultType: evaluateXPath.NUMBER_TYPE }
    );
    var removeCallback = observer.resultsChangedNotifier.addCallback(function () {
        console.log('Currently #' + observer.getResults() + ' footnotes present in this document');
    });
    …
    function destroy () {
        observer.stopObservingQueryResults();
        removeCallback();
    }
    …
});

  Arguments
# Name Type Description
1. selector XPathQuery

An XPath query which will be observed.

2. contextNode Node

The context node from which the XPath query will be evaluated.

3. options Object

Extra options for the index and the XPath

  Members

Members

Name Type Description
expectedResultType Number

The result type of the XPath. See evaluateXPath for more information

namespaceResolver Function
  Arguments
# Name Type Description
1. string
  Returns

Type: String

variables Object

The extra variables which will be used for the XPath. These are not observed

  Returns