Class: TreeComparator

TreeComparator

A class to do discover differences between two DOM trees, calculating a patch, as well as to reconcile those differences by applying the patch

Constructor

new TreeComparator()

Source:

Methods

(static) applyPatches(patches)

Applies the patches to the current DOM.
Parameters:
Name Type Description
patches Patches previously computed with TreeComparator.diff
Source:

(static) diff(node1, node2, comparePolicyopt)

Compute the difference between two DOM trees, giving their root nodes.
The resulting object is a patch object that can be used to keep the first given tree equivalent to the second given tree.
An optional function can be provided to control how different subtrees are compared. This function receives two nodes (node1, node2) and can return:
  • TreeComparator.COMPARE_POLICY_DIFF: The comparison should be done as normal.
  • TreeComparator.COMPARE_POLICY_SKIP: The comparison should not go deeper.
  • TreeComparator.COMPARE_POLICY_REPLACE: The node1 should be totally replaced by the node2, without going deeper
Parameters:
Name Type Attributes Description
node1 Node The root element of the first tree to compare.
node2 Node The root element of the second tree to compare.
comparePolicy function <optional>
An (optional) callback function to be called before comparing subnodes.
Source: