UNPKG

pragma-views2

Version:

60 lines (52 loc) 1.91 kB
import { addEventsFeatures, removeEventsFeatures } from "./mixin-events.js"; import {getValueOnPath} from "./objectpath-helper.js"; export class BaseElement extends HTMLElement { constructor() { super(); } connectedCallback() { addEventsFeatures(this); } disconnectedCallback() { removeEventsFeatures(this); } attributeChangedCallback(name, oldValue, newValue) { const fName = `${name}Changed`; if (this[fName] != undefined) { this[fName](newValue, oldValue); } } labelElements(queries, paths, attributes) { const processCollection = []; for (let i = 0; i < queries.length; i++) { processCollection.push({ element: this.querySelector(queries[i]), path: paths[i], attribute: attributes[i] }); } for (let process of processCollection) { const translation = getValueOnPath(window.translations, process.path); if (process.attribute.toLowerCase() == "innertext") { process.element.innerText = translation; } else { process.element.setAttribute(process.attribute, translation); } } } /** * If you want nulls to be pushed up in the two way coms, set th allowNulls to true * @param name * @param value * @param allowNulls */ notifyPropertyChanged(name, value, allowNulls = false) { if (this.__behaviors == undefined) return; if (value == undefined && allowNulls != true) return; const behaviours = this.__behaviors.filter(item => item._attrName == name.toLowerCase()); for (let behaviour of behaviours) { behaviour.notifyPropertyChanged(name, value); } } }