cyp/app/js/component.js
2020-03-15 23:14:55 +01:00

24 lines
686 B
JavaScript

import Selection from "./selection.js";
export default class Component extends HTMLElement {
constructor(options = {}) {
super();
if (options.selection) { this.selection = new Selection(this, options.selection); }
}
connectedCallback() {
this._app.addEventListener("load", _ => this._onAppLoad());
this._app.addEventListener("component-change", _ => {
const component = this._app.component;
const isThis = (this.nodeName.toLowerCase() == `cyp-${component}`);
this._onComponentChange(component, isThis);
});
}
get _app() { return this.closest("cyp-app"); }
get _mpd() { return this._app.mpd; }
_onAppLoad() {}
_onComponentChange(_component, _isThis) {}
}