dees-element/ts/dees-element.classes.dees-element.ts

47 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2022-03-16 13:46:51 +00:00
import * as plugins from './dees-element.plugins.js';
2021-03-27 16:52:06 +00:00
2021-11-27 16:07:33 +00:00
export class DeesElement extends plugins.lit.LitElement {
2021-03-27 16:52:06 +00:00
// INSTANCE
2021-11-27 16:07:33 +00:00
@plugins.lit.property({ type: Boolean })
2021-03-27 16:52:06 +00:00
public goBright: boolean = false;
// domtools
public domtoolsPromise = plugins.domtools.elementBasic.setup(this);
2021-11-27 16:07:33 +00:00
@plugins.lit.property()
2021-03-27 16:52:06 +00:00
domtools?: plugins.domtools.DomTools;
private themeSubscription: plugins.smartrx.rxjs.Subscription;
2022-01-07 18:47:05 +00:00
private elementDomReadyDeferred = plugins.domtools.plugins.smartpromise.defer();
public elementDomReady = this.elementDomReadyDeferred.promise;
2021-03-27 16:52:06 +00:00
constructor() {
super();
this.domtoolsPromise.then((domtoolsArg) => {
this.domtools = domtoolsArg;
});
}
2022-01-06 20:53:21 +00:00
public async connectedCallback() {
2021-03-27 16:52:06 +00:00
super.connectedCallback();
2022-01-06 21:08:08 +00:00
const domtools = await this.domtoolsPromise;
this.themeSubscription = domtools.themeManager.themeObservable.subscribe((goBrightArg) => {
this.goBright = goBrightArg;
});
2021-03-27 16:52:06 +00:00
this.dispatchEvent(new CustomEvent('deesElementConnected'));
}
2022-01-07 18:47:05 +00:00
public firstUpdated(_changedProperties: Map<string | number | symbol, unknown>): void {
super.firstUpdated(_changedProperties);
this.elementDomReadyDeferred.resolve();
}
2022-01-06 20:53:21 +00:00
public async disconnectedCallback() {
await this.domtoolsPromise;
2021-03-27 16:52:06 +00:00
super.disconnectedCallback();
this.themeSubscription.unsubscribe();
this.dispatchEvent(new CustomEvent('deesElementDisconnected'));
}
}