vue3-yuanma/packages/runtime-dom/src/modules/class.ts
2019-12-18 11:45:28 -05:00

22 lines
744 B
TypeScript

import { ElementWithTransition } from '../components/Transition'
// compiler should normalize class + :class bindings on the same element
// into a single binding ['staticClass', dynamic]
export function patchClass(el: Element, value: string | null, isSVG: boolean) {
if (value == null) {
value = ''
}
// directly setting className should be faster than setAttribute in theory
if (isSVG) {
el.setAttribute('class', value)
} else {
// if this is an element during a transition, take the temporary transition
// classes into account.
const transitionClasses = (el as ElementWithTransition)._vtc
if (transitionClasses) {
value = [value, ...transitionClasses].join(' ')
}
el.className = value
}
}