cyp/app/js/component.js

23 lines
599 B
JavaScript
Raw Normal View History

2020-03-09 05:11:46 +08:00
const APP = "cyp-app";
2020-03-09 16:26:10 +08:00
export class HasApp extends HTMLElement {
get _app() { return this.closest("cyp-app"); }
get _mpd() { return this._app.mpd; }
}
export default class Component extends HasApp {
2020-03-09 05:11:46 +08:00
constructor() {
super();
2020-03-09 16:26:10 +08:00
this._app.addEventListener("load", _ => this._onAppLoad());
this._app.addEventListener("component-change", _ => {
const component = this._app.getAttribute("component");
const isThis = (this.nodeName.toLowerCase() == `cyp-${component}`);
this._onComponentChange(component, isThis);
2020-03-09 05:11:46 +08:00
});
}
2020-03-09 16:26:10 +08:00
_onComponentChange(_component, _isThis) {}
_onAppLoad() {}
2020-03-09 01:06:54 +08:00
}