MCPcopy
hub / github.com/rrweb-io/rrweb / nodeMatching

Function nodeMatching

packages/rrdom/src/diff.ts:599–613  ·  view source on GitHub ↗
(
  node1: Node,
  node2: IRRNode,
  domMirror: NodeMirror,
  rrdomMirror: Mirror,
)

Source from the content-addressed store, hash-verified

597 * To check whether two nodes are matching. If so, they are supposed to have the same serialized Id and node type. If they are both Elements, their tagNames should be the same as well. Otherwise, they are not matching.
598 */
599export function nodeMatching(
600 node1: Node,
601 node2: IRRNode,
602 domMirror: NodeMirror,
603 rrdomMirror: Mirror,
604): boolean {
605 const node1Id = domMirror.getId(node1);
606 const node2Id = rrdomMirror.getId(node2);
607 // rrdom contains elements with negative ids, we don't want to accidentally match those to a mirror mismatch (-1) id.
608 // Negative oldStartId happen when nodes are not in the mirror, but are in the DOM.
609 // eg.iframes come with a document, html, head and body nodes.
610 // thats why below we always check if an id is negative.
611 if (node1Id === -1 || node1Id !== node2Id) return false;
612 return sameNodeType(node1, node2);
613}

Callers 3

diff.test.tsFile · 0.90
diffChildrenFunction · 0.85

Calls 2

sameNodeTypeFunction · 0.85
getIdMethod · 0.65

Tested by

no test coverage detected