@logo-elements/component-base
Version:
A set of mixins used by Logo Elements which is extended from Vaadin components.
72 lines (58 loc) • 2.13 kB
JavaScript
/**
* @license
* Copyright LOGO YAZILIM SANAYİ VE TİCARET A.Ş.
*
* Save to the extent permitted by law, you may not use, copy, modify,
* distribute or create derivative works of this material or any part
* of it without the prior written consent of LOGO YAZILIM SANAYİ VE TİCARET A.Ş. Limited.
* Any reproduction of this material must contain this notice.
*/
import { usageStatistics } from '@vaadin/vaadin-usage-statistics/vaadin-usage-statistics.js';
import { idlePeriod } from './async.js';
import { Debouncer, enqueueDebouncer } from './debounce.js';
import { DirMixin } from './dir-mixin.js';
window.LogoElements = window.LogoElements || {};
/**
* Array of Logo Elements custom element classes that have been finalized.
*/
window.LogoElements.registrations = window.LogoElements.registrations || [];
window.LogoElements.developmentModeCallback = window.LogoElements.developmentModeCallback || {};
window.LogoElements.developmentModeCallback['logo-elements-usage-statistics'] = function () {
usageStatistics();
};
let statsJob;
const registered = new Set();
/**
* @polymerMixin
* @mixes DirMixin
*/
export const ElementMixin = (superClass) =>
class LogoElementsElementMixin extends DirMixin(superClass) {
static get version() {
return '22.0.1';
}
/** @protected */
static finalize() {
super.finalize();
const { is } = this;
// Registers a class prototype for telemetry purposes.
if (is && !registered.has(is)) {
window.LogoElements.registrations.push(this);
registered.add(is);
if (window.LogoElements.developmentModeCallback) {
statsJob = Debouncer.debounce(statsJob, idlePeriod, () => {
window.LogoElements.developmentModeCallback['logo-elements-usage-statistics']();
});
enqueueDebouncer(statsJob);
}
}
}
constructor() {
super();
if (document.doctype === null) {
console.warn(
'Logo Elements components require the "standards mode" declaration. Please add <!DOCTYPE html> to the HTML document.'
);
}
}
};