invalidateNodeListCachesInAncestors method

void invalidateNodeListCachesInAncestors(
  1. ChildrenChange? change
)

Implementation

void invalidateNodeListCachesInAncestors(ChildrenChange? change) {
  // This is a performance optimization, NodeList cache invalidation is
  // not necessary for a text change.
  if (change != null && change.type == ChildrenChangeType.TEXT_CHANGE) {
    return;
  }

  if (nodeData != null) {
    if (nodeData!.nodeList is ChildNodeList) {
      if (change != null) {
        (nodeData!.nodeList as ChildNodeList).childrenChanged(change);
      } else {
        (nodeData!.nodeList as ChildNodeList).invalidateCache();
      }
    }
    if (parentNode != null) {
      ownerDocument.nthIndexCache.invalidateWithParentNode(parentNode!);
    }
  }

  // This is a performance optimization, NodeList cache invalidation is
  // not necessary for non-element nodes.
  if (change != null &&
      change.affectsElements == ChildrenChangeAffectsElements.NO) {
    return;
  }

  ContainerNode? node = this;
  while (node != null) {
    NodeList lists = node.childNodes;
    if (lists is ChildNodeList) {
      lists.invalidateCache();
    }
    node = node.parentNode;
  }
  if (parentNode != null) {
    ownerDocument.nthIndexCache.invalidateWithParentNode(parentNode!);
  }
}