Disconnect unused more-info (#945)

This commit is contained in:
Andrey 2018-02-28 00:00:50 +02:00 committed by Paulus Schoutsen
parent a88c6f49a2
commit ebc21aaa40
2 changed files with 22 additions and 7 deletions

View File

@ -40,6 +40,16 @@ class MoreInfoCamera extends window.hassMixins.EventsMixin(Polymer.Element) {
};
}
connectedCallback() {
super.connectedCallback();
this.isVisible = true;
}
disconnectedCallback() {
this.isVisible = false;
super.disconnectedCallback();
}
imageLoaded() {
this.fire('iron-resize');
}

View File

@ -43,16 +43,21 @@ class MoreInfoContent extends Polymer.Element {
stateObjChanged(stateObj, hass) {
if (!stateObj || !hass) {
// If root has lastChild, set 'isVisible' attribute of that child to false.
if (this.lastChild) {
this.lastChild.isVisible = false;
this._detachedChild = this.lastChild;
// Detach child to prevent it from doing work.
this.removeChild(this.lastChild);
}
} else {
window.hassUtil.dynamicContentUpdater(
this, 'MORE-INFO-' + window.hassUtil.stateMoreInfoType(stateObj).toUpperCase(),
{ hass: hass, stateObj: stateObj, isVisible: true }
);
return;
}
if (this._detachedChild) {
this.appendChild(this._detachedChild);
this._detachedChild = null;
}
window.hassUtil.dynamicContentUpdater(
this, 'MORE-INFO-' + window.hassUtil.stateMoreInfoType(stateObj).toUpperCase(),
{ hass: hass, stateObj: stateObj }
);
}
}