cyp/app/js/component.js

33 lines
736 B
JavaScript
Raw Normal View History

2020-03-09 05:11:46 +08:00
const APP = "cyp-app";
2020-03-09 01:06:54 +08:00
export default class Component extends HTMLElement {
2020-03-09 05:11:46 +08:00
constructor() {
super();
this._app.then(app => {
let mo = new MutationObserver(mrs => {
mrs.forEach(mr => this._onAppAttributeChange(mr));
});
mo.observe(app, {attributes:true});
});
}
_onAppAttributeChange(mr) {
if (mr.attributeName != "component") { return; }
const component = mr.target.getAttribute(mr.attributeName);
const isThis = (this.nodeName.toLowerCase() == `cyp-${component}`);
this._onComponentChange(component, isThis);
}
get _app() {
return customElements.whenDefined(APP)
.then(() => this.closest(APP));
}
get _mpd() {
return this._app.then(app => app.mpd);
}
_onComponentChange(component) {}
2020-03-09 01:06:54 +08:00
}