Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Commit

Permalink
improve template rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
maykar committed May 24, 2020
1 parent d66fe46 commit b882e61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { getLovelace } from 'custom-card-helpers';

export class CustomHeaderConfig {
static buildConfig(ch, lovelace = getLovelace()) {
if (!window.customHeaderUnsub) window.customHeaderUnsub = [];
const haElem = ha_elements();
if (!lovelace || !haElem) return;
clearTimeout(window.customHeaderTempTimeout);
this.default_config = defaultConfig();
this.config = {
...this.default_config,
Expand Down Expand Up @@ -52,6 +52,13 @@ export class CustomHeaderConfig {
if (JSON.stringify(window.last_template_result) == JSON.stringify(this.config)) {
return;
} else {
clearTimeout(window.customHeaderTempTimeout);
if (window.customHeaderUnsub) {
for (const unsub of window.customHeaderUnsub) {
if (typeof unsub === 'function') unsub();
}
}
window.customHeaderUnsub = [];
window.last_template_result = this.config;
}
this.processAndContinue(ch, haElem);
Expand Down Expand Up @@ -83,13 +90,6 @@ export class CustomHeaderConfig {
}

static async catchTemplate() {
if (window.customHeaderUnsub) {
for (const unsub of window.customHeaderUnsub) {
if (typeof unsub === 'function') unsub();
}
}
window.customHeaderUnsub = [];

try {
const unsub = await this.unsub;
window.customHeaderUnsub.push(unsub);
Expand Down
1 change: 1 addition & 0 deletions src/custom-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ if (!window.location.href.includes('disable_ch')) hideHeader();
export const rebuild = () => {
if (ha_elements() && ha_elements().root.querySelector('app-toolbar').className == 'edit-mode') return;
(window as any).last_template_result = [];
clearTimeout((window as any).customHeaderTempTimeout);
if (!window.location.href.includes('disable_ch')) hideHeader();
let timeout;
const haElem = ha_elements();
Expand Down

0 comments on commit b882e61

Please sign in to comment.