UNPKG

vasille

Version:

The first Developer eXperience Orientated front-end framework (core library).

44 lines (43 loc) 1.21 kB
import { Binding } from "./binding.js"; function addClass(node, cl) { node.element.classList.add(cl); } function removeClass(node, cl) { node.element.classList.remove(cl); } export class StaticClassBinding extends Binding { constructor(node, name, value) { super(value); this.current = false; this.init((value) => { if (value !== this.current) { if (value) { addClass(node, name); } else { removeClass(node, name); } this.current = value; } }); } } export class DynamicalClassBinding extends Binding { constructor(node, value) { super(value); this.current = ""; this.init((value) => { /* istanbul ignore else */ if (this.current != value) { if (this.current.length) { removeClass(node, this.current); } /* istanbul ignore else */ if (value.length) { addClass(node, value); } this.current = value; } }); } }