UNPKG

@cran/vue.core

Version:

Cranberry Vue Core Utilities

27 lines (26 loc) 749 B
import { bem, bid } from "@cran/vue.use"; const BEM_FACTORY = Symbol("bem.factory"); const BEM = Symbol("bem"); export function bemDirective(el, binding) { const vm = binding.instance; const prev = el[BEM]; const next = (el[BEM_FACTORY] || (el[BEM_FACTORY] = bem(bid(vm.$options.name, binding.arg))))([binding.value, binding.modifiers,]); if (!prev) { for (const key in next) { el.classList.add(key); } } else { for (const key in next) { if (!prev[key]) { el.classList.add(key); } } for (const key in prev) { if (!next[key]) { el.classList.remove(key); } } } el[BEM] = next; }