import { LitElement } from "lit"; import { Subject } from "rxjs"; export class RxLitElement extends LitElement { $connected = new Subject(); connectedCallback() { super.connectedCallback(); this.$connected.next(true); } disconnectedCallback() { super.disconnectedCallback(); this.$connected.next(false); } #firstUpdate!: boolean; $: any = {}; firstUpdated() { this.#firstUpdate = true; } updated(changedProperties: Map) { if (!this.#firstUpdate) for (const prop of changedProperties.keys()) { if (prop in this.$) this.$[prop].next((this)[prop]); } this.#firstUpdate = false; } fireEvent(name: string, eventInitDict?: CustomEventInit) { this.dispatchEvent(new CustomEvent(name, eventInitDict)); this.dispatchEvent( new CustomEvent(`${this.tagName.toLowerCase()}-${name}`, eventInitDict), ); } } export function applyMixins( derivedCtor: Constructor, baseCtors: Constructor[], ) { baseCtors.forEach((baseCtor) => { Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => { derivedCtor.prototype[name] = baseCtor.prototype[name]; }); }); return derivedCtor; }