diff --git a/src/components/ha-checkbox.ts b/src/components/ha-checkbox.ts index c4ef540352f5..232d663b13a0 100644 --- a/src/components/ha-checkbox.ts +++ b/src/components/ha-checkbox.ts @@ -1,8 +1,9 @@ -import { Constructor, customElement, CSSResult, css } from "lit-element"; +import { customElement, CSSResult, css } from "lit-element"; import "@material/mwc-checkbox"; // tslint:disable-next-line import { Checkbox } from "@material/mwc-checkbox"; import { style } from "@material/mwc-checkbox/mwc-checkbox-css"; +import { Constructor } from "../types"; // tslint:disable-next-line const MwcCheckbox = customElements.get("mwc-checkbox") as Constructor; diff --git a/src/components/ha-fab.ts b/src/components/ha-fab.ts index f7ffee55fefe..2003ac0c41ca 100644 --- a/src/components/ha-fab.ts +++ b/src/components/ha-fab.ts @@ -1,12 +1,8 @@ -import { - classMap, - html, - customElement, - Constructor, -} from "@material/mwc-base/base-element"; +import { classMap, html, customElement } from "@material/mwc-base/base-element"; import { ripple } from "@material/mwc-ripple/ripple-directive.js"; import "@material/mwc-fab"; +import { Constructor } from "../types"; // tslint:disable-next-line import { Fab } from "@material/mwc-fab"; // tslint:disable-next-line diff --git a/src/components/ha-icon.ts b/src/components/ha-icon.ts index 2e2a6ba848af..5d71f214ed79 100644 --- a/src/components/ha-icon.ts +++ b/src/components/ha-icon.ts @@ -1,4 +1,5 @@ -import { Constructor } from "lit-element"; +import { Constructor } from "../types"; + import "@polymer/iron-icon/iron-icon"; // Not duplicate, this is for typing. // tslint:disable-next-line diff --git a/src/components/ha-paper-dropdown-menu.ts b/src/components/ha-paper-dropdown-menu.ts index bed3e0ea1079..72f2f6b15c9e 100644 --- a/src/components/ha-paper-dropdown-menu.ts +++ b/src/components/ha-paper-dropdown-menu.ts @@ -1,6 +1,6 @@ import "@polymer/paper-dropdown-menu/paper-dropdown-menu"; -import { Constructor } from "lit-element"; import { PolymerElement } from "@polymer/polymer"; +import { Constructor } from "../types"; const paperDropdownClass = customElements.get( "paper-dropdown-menu" diff --git a/src/components/ha-paper-icon-button-arrow-next.ts b/src/components/ha-paper-icon-button-arrow-next.ts index 6bf526ec2e43..f0d473038526 100644 --- a/src/components/ha-paper-icon-button-arrow-next.ts +++ b/src/components/ha-paper-icon-button-arrow-next.ts @@ -1,5 +1,5 @@ -import { Constructor } from "lit-element"; import "@polymer/paper-icon-button/paper-icon-button"; +import { Constructor } from "../types"; // Not duplicate, this is for typing. // tslint:disable-next-line import { PaperIconButtonElement } from "@polymer/paper-icon-button/paper-icon-button"; diff --git a/src/components/ha-paper-icon-button-arrow-prev.ts b/src/components/ha-paper-icon-button-arrow-prev.ts index dd6378acadb5..d79c8c66f4e3 100644 --- a/src/components/ha-paper-icon-button-arrow-prev.ts +++ b/src/components/ha-paper-icon-button-arrow-prev.ts @@ -1,5 +1,5 @@ -import { Constructor } from "lit-element"; import "@polymer/paper-icon-button/paper-icon-button"; +import { Constructor } from "../types"; // Not duplicate, this is for typing. // tslint:disable-next-line import { PaperIconButtonElement } from "@polymer/paper-icon-button/paper-icon-button"; diff --git a/src/components/ha-paper-icon-button-next.ts b/src/components/ha-paper-icon-button-next.ts index e3038e5a0061..cca612de4f34 100644 --- a/src/components/ha-paper-icon-button-next.ts +++ b/src/components/ha-paper-icon-button-next.ts @@ -1,5 +1,5 @@ -import { Constructor } from "lit-element"; import "@polymer/paper-icon-button/paper-icon-button"; +import { Constructor } from "../types"; // Not duplicate, this is for typing. // tslint:disable-next-line import { PaperIconButtonElement } from "@polymer/paper-icon-button/paper-icon-button"; diff --git a/src/components/ha-paper-icon-button-prev.ts b/src/components/ha-paper-icon-button-prev.ts index 396482be4b83..ca4c32ff1ce5 100644 --- a/src/components/ha-paper-icon-button-prev.ts +++ b/src/components/ha-paper-icon-button-prev.ts @@ -1,5 +1,5 @@ -import { Constructor } from "lit-element"; import "@polymer/paper-icon-button/paper-icon-button"; +import { Constructor } from "../types"; // Not duplicate, this is for typing. // tslint:disable-next-line import { PaperIconButtonElement } from "@polymer/paper-icon-button/paper-icon-button"; diff --git a/src/components/ha-switch.ts b/src/components/ha-switch.ts index 53b8cf122992..b31909c499ff 100644 --- a/src/components/ha-switch.ts +++ b/src/components/ha-switch.ts @@ -1,8 +1,9 @@ -import { Constructor, customElement, CSSResult, css, query } from "lit-element"; +import { customElement, CSSResult, css, query } from "lit-element"; import "@material/mwc-switch"; import { style } from "@material/mwc-switch/mwc-switch-css"; // tslint:disable-next-line import { Switch } from "@material/mwc-switch"; +import { Constructor } from "../types"; // tslint:disable-next-line const MwcSwitch = customElements.get("mwc-switch") as Constructor; diff --git a/src/mixins/lit-localize-lite-mixin.ts b/src/mixins/lit-localize-lite-mixin.ts index 59a90f536460..c99d32c5a81f 100644 --- a/src/mixins/lit-localize-lite-mixin.ts +++ b/src/mixins/lit-localize-lite-mixin.ts @@ -1,45 +1,20 @@ -import { - Constructor, - LitElement, - PropertyDeclarations, - PropertyValues, -} from "lit-element"; -import { getLocalLanguage } from "../util/hass-translation"; -import { localizeLiteBaseMixin } from "./localize-lite-base-mixin"; +import { LitElement, PropertyValues, property } from "lit-element"; +import { getLocalLanguage, getTranslation } from "../util/hass-translation"; import { computeLocalize, LocalizeFunc } from "../common/translations/localize"; +import { Constructor, Resources } from "../types"; const empty = () => ""; -interface LitLocalizeLiteMixin { - language: string; - resources: {}; - translationFragment: string; - localize: LocalizeFunc; -} - -export const litLocalizeLiteMixin = ( - superClass: Constructor -): Constructor => - // @ts-ignore - class extends localizeLiteBaseMixin(superClass) { - // Decorators not possible in anonymous classes - // And also, we cannot declare the variable without overriding the Lit setter. - static get properties(): PropertyDeclarations { - return { - localize: {}, - language: {}, - resources: {}, - translationFragment: {}, - }; - } - - constructor() { - super(); - // This will prevent undefined errors if called before connected to DOM. - this.localize = empty; - // Use browser language setup before login. - this.language = getLocalLanguage(); - } +export const litLocalizeLiteMixin = >( + superClass: T +) => { + class LitLocalizeLiteClass extends superClass { + // Initialized to empty will prevent undefined errors if called before connected to DOM. + @property() public localize: LocalizeFunc = empty; + @property() public resources?: Resources; + // Use browser language setup before login. + @property() public language?: string = getLocalLanguage(); + @property() public translationFragment?: string; public connectedCallback(): void { super.connectedCallback(); @@ -51,7 +26,7 @@ export const litLocalizeLiteMixin = ( ); } - public updated(changedProperties: PropertyValues) { + protected updated(changedProperties: PropertyValues) { super.updated(changedProperties); if ( changedProperties.has("language") || @@ -64,4 +39,38 @@ export const litLocalizeLiteMixin = ( ); } } - }; + + protected async _initializeLocalizeLite() { + if (this.resources) { + return; + } + + if (!this.translationFragment) { + // In dev mode, we will issue a warning if after a second we are still + // not configured correctly. + if (__DEV__) { + setTimeout( + () => + !this.resources && + // tslint:disable-next-line + console.error( + "Forgot to pass in resources or set translationFragment for", + this.nodeName + ), + 1000 + ); + } + return; + } + + const { language, data } = await getTranslation( + this.translationFragment!, + this.language! + ); + this.resources = { + [language]: data, + }; + } + } + return LitLocalizeLiteClass; +}; diff --git a/src/mixins/localize-lite-base-mixin.ts b/src/mixins/localize-lite-base-mixin.ts deleted file mode 100644 index 83fbd612afe4..000000000000 --- a/src/mixins/localize-lite-base-mixin.ts +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Lite base mixin to add localization without depending on the Hass object. - */ -import { getTranslation } from "../util/hass-translation"; -import { Resources } from "../types"; - -/** - * @polymerMixin - */ -export const localizeLiteBaseMixin = (superClass) => - class extends superClass { - public resources?: Resources; - public language?: string; - public translationFragment?: string; - - protected _initializeLocalizeLite() { - if (this.resources) { - return; - } - - if (!this.translationFragment) { - // In dev mode, we will issue a warning if after a second we are still - // not configured correctly. - if (__DEV__) { - setTimeout( - () => - !this.resources && - // tslint:disable-next-line - console.error( - "Forgot to pass in resources or set translationFragment for", - this.nodeName - ), - 1000 - ); - } - return; - } - - this._downloadResources(); - } - - private async _downloadResources() { - const { language, data } = await getTranslation( - this.translationFragment!, - this.language! - ); - this.resources = { - [language]: data, - }; - } - }; diff --git a/src/mixins/localize-lite-mixin.ts b/src/mixins/localize-lite-mixin.ts deleted file mode 100644 index 8fcf11297297..000000000000 --- a/src/mixins/localize-lite-mixin.ts +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Lite mixin to add localization without depending on the Hass object. - */ -import { dedupingMixin } from "@polymer/polymer/lib/utils/mixin"; -import { getLocalLanguage } from "../util/hass-translation"; -import { localizeLiteBaseMixin } from "./localize-lite-base-mixin"; -import { computeLocalize } from "../common/translations/localize"; - -/** - * @polymerMixin - */ -export const localizeLiteMixin = dedupingMixin( - (superClass) => - class extends localizeLiteBaseMixin(superClass) { - static get properties() { - return { - language: { - type: String, - // Use browser language setup before login. - value: getLocalLanguage(), - }, - resources: Object, - // The fragment to load. - translationFragment: String, - /** - * Translates a string to the current `language`. Any parameters to the - * string should be passed in order, as follows: - * `localize(stringKey, param1Name, param1Value, param2Name, param2Value)` - */ - localize: { - type: Function, - computed: "__computeLocalize(language, resources, formats)", - }, - }; - } - - public ready() { - super.ready(); - this._initializeLocalizeLite(); - } - - protected __computeLocalize(language, resources, formats?) { - return computeLocalize( - this.constructor.prototype, - language, - resources, - formats - ); - } - } -); diff --git a/src/mixins/provide-hass-lit-mixin.ts b/src/mixins/provide-hass-lit-mixin.ts index 3b45ecedbe32..fb9d1b3e930f 100644 --- a/src/mixins/provide-hass-lit-mixin.ts +++ b/src/mixins/provide-hass-lit-mixin.ts @@ -1,5 +1,5 @@ -import { UpdatingElement, Constructor, PropertyValues } from "lit-element"; -import { HomeAssistant } from "../types"; +import { UpdatingElement, PropertyValues } from "lit-element"; +import { HomeAssistant, Constructor } from "../types"; export interface ProvideHassElement { provideHass(element: HTMLElement); @@ -7,9 +7,9 @@ export interface ProvideHassElement { /* tslint:disable */ -export const ProvideHassLitMixin = ( - superClass: Constructor -): Constructor => +export const ProvideHassLitMixin = >( + superClass: T +) => // @ts-ignore class extends superClass { protected hass!: HomeAssistant; diff --git a/src/mixins/subscribe-mixin.ts b/src/mixins/subscribe-mixin.ts index 95b31e5eeb9d..350055d232e3 100644 --- a/src/mixins/subscribe-mixin.ts +++ b/src/mixins/subscribe-mixin.ts @@ -1,32 +1,21 @@ -import { - LitElement, - Constructor, - PropertyValues, - PropertyDeclarations, -} from "lit-element"; +import { LitElement, PropertyValues, property } from "lit-element"; import { UnsubscribeFunc } from "home-assistant-js-websocket"; +import { HomeAssistant, Constructor } from "../types"; export interface HassSubscribeElement { hassSubscribe(): UnsubscribeFunc[]; } /* tslint:disable-next-line */ -export const SubscribeMixin = ( - superClass: Constructor -): Constructor => - // @ts-ignore - class extends superClass { +export const SubscribeMixin = >( + superClass: T +) => { + class SubscribeClass extends superClass { + @property() public hass?: HomeAssistant; + /* tslint:disable-next-line */ private __unsubs?: UnsubscribeFunc[]; - // Decorators not possible in anonymous classes - // And also, we cannot declare the variable without overriding the Lit setter. - static get properties(): PropertyDeclarations { - return { - hass: {}, - }; - } - public connectedCallback() { super.connectedCallback(); this.__checkSubscribed(); @@ -57,11 +46,12 @@ export const SubscribeMixin = ( if ( this.__unsubs !== undefined || !((this as unknown) as Element).isConnected || - // @ts-ignore this.hass === undefined ) { return; } this.__unsubs = this.hassSubscribe(); } - }; + } + return SubscribeClass; +}; diff --git a/src/state/auth-mixin.ts b/src/state/auth-mixin.ts index c97730ac3f02..baf012cfdc9e 100644 --- a/src/state/auth-mixin.ts +++ b/src/state/auth-mixin.ts @@ -1,8 +1,8 @@ import { clearState } from "../util/ha-pref-storage"; import { askWrite } from "../common/auth/token_storage"; import { subscribeUser, userCollection } from "../data/ws-user"; -import { Constructor, LitElement } from "lit-element"; import { HassBaseEl } from "./hass-base-mixin"; +import { Constructor } from "../types"; declare global { // for fire event @@ -11,7 +11,7 @@ declare global { } } -export default (superClass: Constructor) => +export default >(superClass: T) => class extends superClass { protected firstUpdated(changedProps) { super.firstUpdated(changedProps); diff --git a/src/state/connection-mixin.ts b/src/state/connection-mixin.ts index eb439c813568..5712b1439253 100644 --- a/src/state/connection-mixin.ts +++ b/src/state/connection-mixin.ts @@ -17,12 +17,12 @@ import hassCallApi from "../util/hass-call-api"; import { subscribePanels } from "../data/ws-panels"; import { forwardHaptic } from "../data/haptics"; import { fireEvent } from "../common/dom/fire_event"; -import { Constructor, LitElement } from "lit-element"; +import { Constructor } from "../types"; import { HassBaseEl } from "./hass-base-mixin"; import { broadcastConnectionStatus } from "../data/connection-status"; -export const connectionMixin = ( - superClass: Constructor +export const connectionMixin = >( + superClass: T ) => class extends superClass { protected initializeHass(auth: Auth, conn: Connection) { @@ -90,13 +90,13 @@ export const connectionMixin = ( conn.sendMessage(msg); }, // For messages that expect a response - callWS: (msg) => { + callWS: (msg) => { if (__DEV__) { // tslint:disable-next-line: no-console console.log("Sending", msg); } - const resp = conn.sendMessagePromise(msg); + const resp = conn.sendMessagePromise(msg); if (__DEV__) { resp.then( diff --git a/src/state/dialog-manager-mixin.ts b/src/state/dialog-manager-mixin.ts index 5fcae876a376..f6e525b5fc99 100644 --- a/src/state/dialog-manager-mixin.ts +++ b/src/state/dialog-manager-mixin.ts @@ -1,7 +1,7 @@ -import { Constructor, LitElement } from "lit-element"; import { HASSDomEvent } from "../common/dom/fire_event"; import { HassBaseEl } from "./hass-base-mixin"; import { makeDialogManager, showDialog } from "../dialogs/make-dialog-manager"; +import { Constructor } from "../types"; interface RegisterDialogParams { dialogShowEvent: keyof HASSDomEvents; @@ -20,8 +20,8 @@ declare global { } } -export const dialogManagerMixin = ( - superClass: Constructor +export const dialogManagerMixin = >( + superClass: T ) => class extends superClass { protected firstUpdated(changedProps) { diff --git a/src/state/disconnect-toast-mixin.ts b/src/state/disconnect-toast-mixin.ts index a36ec359ff81..e2b6aeb14e09 100644 --- a/src/state/disconnect-toast-mixin.ts +++ b/src/state/disconnect-toast-mixin.ts @@ -1,8 +1,8 @@ -import { Constructor, LitElement } from "lit-element"; import { HassBaseEl } from "./hass-base-mixin"; import { showToast } from "../util/toast"; +import { Constructor } from "../types"; -export default (superClass: Constructor) => +export default >(superClass: T) => class extends superClass { protected firstUpdated(changedProps) { super.firstUpdated(changedProps); diff --git a/src/state/haptic-mixin.ts b/src/state/haptic-mixin.ts index 44c02664c9e1..3fe9adea6947 100644 --- a/src/state/haptic-mixin.ts +++ b/src/state/haptic-mixin.ts @@ -1,8 +1,8 @@ -import { Constructor, LitElement, PropertyValues } from "lit-element"; +import { PropertyValues } from "lit-element"; import { HassBaseEl } from "./hass-base-mixin"; import { HapticType } from "../data/haptics"; -import { HomeAssistant } from "../types"; +import { HomeAssistant, Constructor } from "../types"; import { HASSDomEvent } from "../common/dom/fire_event"; import { storeState } from "../util/ha-pref-storage"; @@ -35,7 +35,7 @@ const handleHaptic = (hapticTypeEvent: HASSDomEvent) => { navigator.vibrate(hapticPatterns[hapticTypeEvent.detail]); }; -export const hapticMixin = (superClass: Constructor) => +export const hapticMixin = >(superClass: T) => class extends superClass { protected firstUpdated(changedProps: PropertyValues) { super.firstUpdated(changedProps); diff --git a/src/state/hass-base-mixin.ts b/src/state/hass-base-mixin.ts index 81c4e0689916..34bd9eebaec6 100644 --- a/src/state/hass-base-mixin.ts +++ b/src/state/hass-base-mixin.ts @@ -1,77 +1,51 @@ -import { - Constructor, - // @ts-ignore - property, - PropertyDeclarations, -} from "lit-element"; -import { Auth, Connection } from "home-assistant-js-websocket"; +import { LitElement, property } from "lit-element"; import { HomeAssistant } from "../types"; +import { Auth, Connection } from "home-assistant-js-websocket"; -/* tslint:disable */ - -export class HassBaseEl { - protected hass?: HomeAssistant; +export class HassBaseEl extends LitElement { + @property() public hass?: HomeAssistant; protected _pendingHass: Partial = {}; - protected initializeHass(_auth: Auth, _conn: Connection) {} - protected hassConnected() {} - protected hassReconnected() {} - protected hassDisconnected() {} - protected hassChanged(_hass: HomeAssistant, _oldHass?: HomeAssistant) {} - protected panelUrlChanged(_newPanelUrl: string) {} - public provideHass(_el: HTMLElement) {} - protected _updateHass(_obj: Partial) {} + // tslint:disable-next-line: variable-name + private __provideHass: HTMLElement[] = []; + + public provideHass(el) { + this.__provideHass.push(el); + el.hass = this.hass; + } + + protected initializeHass(_auth: Auth, _conn: Connection) { + // implemented in connection-mixin + // tslint:disable-next-line + } + + // Exists so all methods can safely call super method + protected hassConnected() { + // tslint:disable-next-line + } + + protected hassReconnected() { + // tslint:disable-next-line + } + + protected hassDisconnected() { + // tslint:disable-next-line + } + + protected panelUrlChanged(_newPanelUrl) { + // tslint:disable-next-line + } + + protected hassChanged(hass, _oldHass) { + this.__provideHass.forEach((el) => { + (el as any).hass = hass; + }); + } + + protected _updateHass(obj: Partial) { + if (!this.hass) { + this._pendingHass = { ...this._pendingHass, ...obj }; + return; + } + this.hass = { ...this.hass, ...obj }; + } } - -export default (superClass: Constructor): Constructor => - // @ts-ignore - class extends superClass { - protected _pendingHass: Partial = {}; - private __provideHass: HTMLElement[] = []; - - // Decorators not possible in anonymous classes - // And also, we cannot declare the variable without overriding the Lit setter. - static get properties(): PropertyDeclarations { - return { - hass: {}, - }; - } - - // Exists so all methods can safely call super method - protected hassConnected() { - // tslint:disable-next-line - } - - protected hassReconnected() { - // tslint:disable-next-line - } - - protected hassDisconnected() { - // tslint:disable-next-line - } - - protected panelUrlChanged(_newPanelUrl) { - // tslint:disable-next-line - } - - protected hassChanged(hass, _oldHass) { - this.__provideHass.forEach((el) => { - (el as any).hass = hass; - }); - } - - public provideHass(el) { - this.__provideHass.push(el); - // @ts-ignore - el.hass = this.hass; - } - - protected _updateHass(obj: Partial) { - // @ts-ignore - if (!this.hass) { - this._pendingHass = { ...this._pendingHass, ...obj }; - return; - } - // @ts-ignore - this.hass = { ...this.hass, ...obj }; - } - }; diff --git a/src/state/hass-element.ts b/src/state/hass-element.ts index c225ef9224e6..9aaa9ccc6ac6 100644 --- a/src/state/hass-element.ts +++ b/src/state/hass-element.ts @@ -1,4 +1,3 @@ -import HassBaseMixin from "./hass-base-mixin"; import AuthMixin from "./auth-mixin"; import TranslationsMixin from "./translations-mixin"; import ThemesMixin from "./themes-mixin"; @@ -11,12 +10,13 @@ import NotificationMixin from "./notification-mixin"; import DisconnectToastMixin from "./disconnect-toast-mixin"; import { hapticMixin } from "./haptic-mixin"; import { urlSyncMixin } from "./url-sync-mixin"; -import { LitElement } from "lit-element"; +import { Constructor } from "../types"; +import { HassBaseEl } from "./hass-base-mixin"; -const ext = (baseClass: T, mixins): T => +const ext = (baseClass: T, mixins): T => mixins.reduceRight((base, mixin) => mixin(base), baseClass); -export class HassElement extends ext(HassBaseMixin(LitElement), [ +export class HassElement extends ext(HassBaseEl, [ AuthMixin, ThemesMixin, TranslationsMixin, diff --git a/src/state/more-info-mixin.ts b/src/state/more-info-mixin.ts index 9cd8a129390c..8b3af120d505 100644 --- a/src/state/more-info-mixin.ts +++ b/src/state/more-info-mixin.ts @@ -1,6 +1,5 @@ -import { Constructor, LitElement } from "lit-element"; - import { HassBaseEl } from "./hass-base-mixin"; +import { Constructor } from "../types"; declare global { // for fire event @@ -11,7 +10,7 @@ declare global { } } -export default (superClass: Constructor) => +export default >(superClass: T) => class extends superClass { private _moreInfoEl?: any; diff --git a/src/state/notification-mixin.ts b/src/state/notification-mixin.ts index 726f335052d6..5149e3a80c0a 100644 --- a/src/state/notification-mixin.ts +++ b/src/state/notification-mixin.ts @@ -1,7 +1,11 @@ -export default (superClass) => +import { HassBaseEl } from "./hass-base-mixin"; +import { Constructor } from "../types"; + +export default >(superClass: T) => class extends superClass { protected firstUpdated(changedProps) { super.firstUpdated(changedProps); + // @ts-ignore this.registerDialog({ dialogShowEvent: "hass-notification", dialogTag: "notification-manager", diff --git a/src/state/sidebar-mixin.ts b/src/state/sidebar-mixin.ts index 0432be00147e..456ec7120bd1 100644 --- a/src/state/sidebar-mixin.ts +++ b/src/state/sidebar-mixin.ts @@ -1,8 +1,7 @@ import { storeState } from "../util/ha-pref-storage"; -import { Constructor, LitElement } from "lit-element"; import { HassBaseEl } from "./hass-base-mixin"; import { HASSDomEvent } from "../common/dom/fire_event"; -import { HomeAssistant } from "../types"; +import { HomeAssistant, Constructor } from "../types"; interface DockSidebarParams { dock: HomeAssistant["dockedSidebar"]; @@ -19,7 +18,7 @@ declare global { } } -export default (superClass: Constructor) => +export default >(superClass: T) => class extends superClass { protected firstUpdated(changedProps) { super.firstUpdated(changedProps); diff --git a/src/state/themes-mixin.ts b/src/state/themes-mixin.ts index b97419237ee4..4fd14c823af9 100644 --- a/src/state/themes-mixin.ts +++ b/src/state/themes-mixin.ts @@ -1,9 +1,9 @@ import applyThemesOnElement from "../common/dom/apply_themes_on_element"; import { storeState } from "../util/ha-pref-storage"; import { subscribeThemes } from "../data/ws-themes"; -import { Constructor, LitElement } from "lit-element"; import { HassBaseEl } from "./hass-base-mixin"; import { HASSDomEvent } from "../common/dom/fire_event"; +import { Constructor } from "../types"; declare global { // for add event listener @@ -12,7 +12,7 @@ declare global { } } -export default (superClass: Constructor) => +export default >(superClass: T) => class extends superClass { protected firstUpdated(changedProps) { super.firstUpdated(changedProps); diff --git a/src/state/translations-mixin.ts b/src/state/translations-mixin.ts index edce6341cc73..da7c3f2f3fd0 100644 --- a/src/state/translations-mixin.ts +++ b/src/state/translations-mixin.ts @@ -4,11 +4,10 @@ import { getLocalLanguage, getUserLanguage, } from "../util/hass-translation"; -import { Constructor, LitElement } from "lit-element"; import { HassBaseEl } from "./hass-base-mixin"; import { computeLocalize } from "../common/translations/localize"; import { computeRTL } from "../common/util/compute_rtl"; -import { HomeAssistant } from "../types"; +import { HomeAssistant, Constructor } from "../types"; import { storeState } from "../util/ha-pref-storage"; import { getHassTranslations, @@ -19,7 +18,7 @@ import { * superClass needs to contain `this.hass` and `this._updateHass`. */ -export default (superClass: Constructor) => +export default >(superClass: T) => class extends superClass { // tslint:disable-next-line: variable-name private __coreProgress?: string; diff --git a/src/state/url-sync-mixin.ts b/src/state/url-sync-mixin.ts index 920066bd8514..94325cab7bb8 100644 --- a/src/state/url-sync-mixin.ts +++ b/src/state/url-sync-mixin.ts @@ -1,12 +1,12 @@ -import { Constructor, LitElement } from "lit-element"; import { HassBaseEl } from "./hass-base-mixin"; import { fireEvent } from "../common/dom/fire_event"; +import { Constructor } from "../types"; /* tslint:disable:no-console */ const DEBUG = false; -export const urlSyncMixin = ( - superClass: Constructor +export const urlSyncMixin = >( + superClass: T ) => // Disable this functionality in the demo. __DEMO__ diff --git a/src/state/zha-dialog-mixin.ts b/src/state/zha-dialog-mixin.ts index 600c9c49723f..ba6e294c2dbd 100644 --- a/src/state/zha-dialog-mixin.ts +++ b/src/state/zha-dialog-mixin.ts @@ -1,10 +1,11 @@ -import { Constructor, LitElement } from "lit-element"; +import { UpdatingElement } from "lit-element"; import { HassBaseEl } from "./hass-base-mixin"; import { showZHADeviceInfoDialog, ZHADeviceInfoDialogParams, } from "../dialogs/zha-device-info-dialog/show-dialog-zha-device-info"; import { HASSDomEvent } from "../common/dom/fire_event"; +import { Constructor } from "../types"; declare global { // for fire event @@ -15,7 +16,7 @@ declare global { } } -export default (superClass: Constructor) => +export default (superClass: Constructor) => class extends superClass { protected firstUpdated(changedProps) { super.firstUpdated(changedProps); diff --git a/src/types.ts b/src/types.ts index d67d460285d7..4288597623a7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -40,6 +40,8 @@ declare global { } } +export type Constructor = new (...args: any[]) => T; + export interface WebhookError { code: number; message: string;