NodeProxy

Type: Class

Provides a layer around a given node using which access to the node can be intercepted. This will enable Fonto to automatically update the correct parts of a view when the data related to the node that is used in that view changes.

This constructor should not be used by applications. Instances of NodeProxy are obtained when rendering custom widgets or when generating the innerJsonMl for a member of the object CVK family.

Constructor

# Name Type Description
1. node Node

The node to wrap

2. dependencies Dependencies

Dependencies to populate according to how the node is accessed

3. flags ViewFlags

View flags for the current view

4. requestUpdate Function

Called to request a view update when an external state change invalidates a dependency

5. nodeProxyContext WeakMap

Weakmap from node to the corresponding NodeProxy, to guarantee that proxies obtained for the same node are always reference-equal.

Properties

Name Type Description
attributes Array<Attr>

Returns the node's attributes, assuming it is an Element.

childCount Number

Returns the number of child nodes of the node.

childElementCount Number

Returns the number of child elements of the node, assuming it is an Element.

childNodes Array<NodeProxy>

Returns NodeProxies for all childNodes under the current node

This introduces dependencies on the childNodes property of this node

data String

Returns the node's data, assuming it is a CharacterData instance.

firstChild NodeProxy

Returns a nodeProxy for the first child of the current node

This introduces dependencies on the childNodes property of this node

lastChild NodeProxy

Returns a nodeProxy for the first child of the current node

This introduces dependencies on the childNodes property of this node

length Number

Returns the length of the node, assuming it is a CharacterData instance.

nextSibling NodeProxy

Returns a nodeProxy for the next sibling of the current node

This introduces dependencies on the childNodes property of this node's parentNode

parentNode NodeProxy

Returns a NodeProxy for the parentNode of this node.

previousSibling NodeProxy

Returns a nodeProxy for the previous sibling of the current node

This introduces dependencies on the childNodes property of this node's parentNode

Methods

Name Description
documentMeetsRequiredAspects

Similar to DocumentsManager#documentMeetsRequiredAspects, but ensures the fragment updates when these aspects change.


  Arguments
# Name Type Description
1. requiredAspects Object
  Returns

Type: Boolean

findDescendants

Find all descendants of this node matching the descendantSelector.

Using this query avoids recomputing possibly heavy queries every time something under this node changes, replacing it by an indexed lookup.


  Arguments
# Name Type Description
1. descendantSelector XPathTest

XPath test expression determining which descendants to return

  Returns

Type: Array<NodeProxy>

All descendants matching the selector

findRelatedNodes

Perform a complex query for other nodes in the document, starting at the current sourceNode. Using this method avoids taking dependencies on any intermediate result other than the result of the query, which prevents unnecessary redraws.

DO NOT use any node from findRelatedNode's closure in the query, as that would result in extra dependencies.

Example: (find all nodes with the same data as the current node)

var interestingData = innerNode.firstChild.data;
sourceNode.findRelatedNodes(function query (innerNode) {
    var interestingAncestor = domUtils.findClosestAncestor(innerNode, 'interesting');
    return domQuery.findDescendants(interestingAncestor, 'evenMoreInteresting')
        .filter(node) {
            return node.firstChild.data === interestingData;
        });
});

Because this selector could change often, NodeProxy#findRelatedNodes is a better fit for this problem than NodeProxy#findDescendants


  Arguments
# Name Type Description
1. findRelatedNodes Function
  Arguments
# Name Type Description
1. NodeProxy
  Returns

Type: Array<NodeProxy>

  Returns

Type: Array<NodeProxy>

The result of the query

getAttribute

Returns the value of the attribute with the given name for the current element, or null if the attribute doesn't exist.


  Arguments
# Name Type Description
1. attributeName String

The name of the attribute to search for.

  Returns

Type: String | Null

The value of the attribute.

getAttributeNS

Returns the value of the attribute with the given local name and namespace for the current element, or null if the attribute doesn't exist.


  Arguments
# Name Type Description
1. namespaceUri String | Null
2. localName String
  Returns

Type: String | Null

The value of the attribute.

getExternalValue

Retrieve an external value, not represented in the current document.

Use ExternalDataManager#setExternalData to modify external data values.


  Arguments
# Name Type Description
1. name String

The registered name for the dataSource, in externalDataManager

  Returns

Type: any

The current value of the dataSource

getViewFlag

Retrieves a boolean indicating whether the specified view flag is set.


  Arguments
# Name Type Description
1. name String
  Returns

Type: Boolean

hasAttribute

Returns whether the node has an attribute with the given name


  Arguments
# Name Type Description
1. qualifiedName String
  Returns

Type: Boolean

Whether the attribute is present

hasAttributeNS

Returns whether the node has an attribute with the given local name and namespace


  Arguments
# Name Type Description
1. namespaceUri String | Null
2. localName String
  Returns

Type: Boolean

Whether the attribute is present

substringData

Returns a string containing the part of CharacterData.data of the specified length and starting at the specified offset.


  Arguments
# Name Type Description
1. offset Number

An integer between 0 and the length of the string.

2. [count] Number

An integer between 0 and the length of the string.

  Returns

Type: String

The substring extracted from the textual data of the CharacterData node.