Stability improvements

This commit is contained in:
Thomas Lovén 2019-06-09 20:28:18 +02:00
parent c84ea8e09c
commit ea12cc6629
3 changed files with 76 additions and 73 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
card-mod.js binary

File diff suppressed because one or more lines are too long

View File

@ -2,9 +2,10 @@ import {html, css} from "/card-tools/lit-element.js";
import {fireEvent} from "/card-tools/event.js"; import {fireEvent} from "/card-tools/event.js";
import {parseTemplate} from "/card-tools/templates.js"; import {parseTemplate} from "/card-tools/templates.js";
const HaCard = customElements.get('ha-card'); customElements.whenDefined('ha-card').then(() => {
const HaCard = customElements.get('ha-card');
const findConfig = function(node) { const findConfig = function(node) {
if(node.config) if(node.config)
return node.config; return node.config;
if(node._config) if(node._config)
@ -16,9 +17,9 @@ const findConfig = function(node) {
if(node.parentNode) if(node.parentNode)
return findConfig(node.parentNode); return findConfig(node.parentNode);
return null; return null;
}; };
const applyStyle = function(root, style) { const applyStyle = function(root, style) {
if(!root || !style) return; if(!root || !style) return;
if(typeof style === "string") { if(typeof style === "string") {
@ -45,16 +46,16 @@ const applyStyle = function(root, style) {
} }
}); });
} }
} }
HaCard.prototype.updated = function(_) { HaCard.prototype.updated = function(_) {
// Apply styles after updates, if specified // Apply styles after updates, if specified
const config = findConfig(this); const config = findConfig(this);
if(config && config.style) if(config && config.style)
applyStyle(this, config.style); applyStyle(this, config.style);
} }
HaCard.prototype.firstUpdated = function() { HaCard.prototype.firstUpdated = function() {
// Move the header inside the slot instead of in the shadowDOM // Move the header inside the slot instead of in the shadowDOM
// makes it easier to style it consistently // makes it easier to style it consistently
const header = this.shadowRoot.querySelector(".card-header"); const header = this.shadowRoot.querySelector(".card-header");
@ -65,8 +66,8 @@ HaCard.prototype.firstUpdated = function() {
// Listen for changes to hass or the location and update // Listen for changes to hass or the location and update
document.querySelector("home-assistant").provideHass(this); document.querySelector("home-assistant").provideHass(this);
window.addEventListener("location-changed", () => this._requestUpdate()); window.addEventListener("location-changed", () => this._requestUpdate());
} }
Object.defineProperty(HaCard.prototype, 'hass', { Object.defineProperty(HaCard.prototype, 'hass', {
get() { get() {
return this._hass; return this._hass;
}, },
@ -77,6 +78,7 @@ Object.defineProperty(HaCard.prototype, 'hass', {
this._requestUpdate('hass', oldval); this._requestUpdate('hass', oldval);
} }
}, },
}); });
fireEvent('ll-rebuild', {}); fireEvent('ll-rebuild', {});
});