@aurelia-mdc-web/base
Version:
Base classes for Aurelia Material Components Web
68 lines • 2.42 kB
JavaScript
import { __awaiter } from "tslib";
export class MdcComponent {
constructor(root) {
this.root = root;
this.initialised = this.createInitiliasedPromise();
}
createInitiliasedPromise() {
return __awaiter(this, void 0, void 0, function* () {
return new Promise(r => this.initialisedResolve = r);
});
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
initialise() {
return __awaiter(this, void 0, void 0, function* () { });
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
initialSyncWithDOM() { }
attached() {
return __awaiter(this, void 0, void 0, function* () {
this.continueAttaching = true;
yield this.initialise();
// detached might be called straight after attached starts
// do not continue attaching if that's the case
if (!this.continueAttaching) {
return;
}
this.foundation = this.getDefaultFoundation();
this.foundation.init();
this.initialisedResolve();
this.initialSyncWithDOM();
});
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
destroy() { }
detached() {
var _a;
this.continueAttaching = false;
this.destroy();
(_a = this.foundation) === null || _a === void 0 ? void 0 : _a.destroy();
this.foundation = undefined;
this.initialised = this.createInitiliasedPromise();
}
listen(evtType, handler, options) {
this.root.addEventListener(evtType, handler, options);
}
unlisten(evtType, handler, options) {
this.root.removeEventListener(evtType, handler, options);
}
/**
* @hidden
* Fires a cross-browser-compatible custom event from the component root of the given type, with the given data.
*/
emit(evtType, evtData, shouldBubble = false) {
let evt;
if (typeof CustomEvent === 'function') {
evt = new CustomEvent(evtType, {
bubbles: shouldBubble,
detail: evtData,
});
}
else {
evt = document.createEvent('CustomEvent');
evt.initCustomEvent(evtType, shouldBubble, false, evtData);
}
this.root.dispatchEvent(evt);
}
}
//# sourceMappingURL=mdc-component.js.map