all files / src/patchVNode/ updateElement.ts

100% Statements 11/11
100% Branches 4/4
100% Functions 2/2
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21   233×   233× 231×   231×   230×     233×     233×    
import { ElementVNode, SCOPE_ATTRIBUTE, VNode } from '../'
 
export function updateElement(formerVNode: VNode, vNode: VNode): ElementVNode {
  const node = vNode.element = formerVNode.element as Node
 
  if (isElement(node)) {
    const { scope } = vNode
 
    if (scope)
      node.setAttribute(SCOPE_ATTRIBUTE, scope)
    else
      node.removeAttribute(SCOPE_ATTRIBUTE)
  }
 
  return vNode as ElementVNode
}
 
function isElement(node: Node): node is Element {
  return typeof (node as Element).setAttribute === 'function'
}