All files / src/virtual-dom/helpers/dom patchNode.ts

62.5% Statements 5/8
50% Branches 1/2
100% Functions 1/1
62.5% Lines 5/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22  5x   5x   2x   2x   2x                        
import { VirtualNode } from "../../interfaces";
import createNode from "./createNode";
 
export default function patchNode(newVNode: VirtualNode, oldVNode: VirtualNode, document: Document): Node {
 
    const oldElement = oldVNode.$node;
 
    Eif (newVNode.tag === oldVNode.tag) { // Check if the attributes and children changed
 
        return oldElement;
 
    }
    else { // Different tags, replace the element
 
        const newElement = createNode(newVNode);
 
        oldElement.parentNode.replaceChild(newElement, oldElement);
 
        return newElement;
    }
 
}