[logbook] implement shouldUpdate (#4832)

* [logbook] implement shouldUpdate

* Update src/panels/logbook/ha-logbook.ts

Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Ruslan Sayfutdinov 2020-02-11 23:26:28 +00:00 committed by GitHub
parent 1437b4c4b6
commit d48a4e0ac6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 12 deletions

View File

@ -59,7 +59,7 @@ class HaLogbookData extends PolymerElement {
this._setIsLoading(true); this._setIsLoading(true);
this.getDate(this.filterDate, this.filterPeriod, this.filterEntity).then( this.getData(this.filterDate, this.filterPeriod, this.filterEntity).then(
(logbookEntries) => { (logbookEntries) => {
this._setEntries(logbookEntries); this._setEntries(logbookEntries);
this._setIsLoading(false); this._setIsLoading(false);
@ -67,7 +67,7 @@ class HaLogbookData extends PolymerElement {
); );
} }
getDate(date, period, entityId) { getData(date, period, entityId) {
if (!entityId) entityId = ALL_ENTITIES; if (!entityId) entityId = ALL_ENTITIES;
if (!DATA_CACHE[period]) DATA_CACHE[period] = []; if (!DATA_CACHE[period]) DATA_CACHE[period] = [];

View File

@ -25,19 +25,14 @@ class HaLogbook extends LitElement {
// @ts-ignore // @ts-ignore
private _rtl = false; private _rtl = false;
protected updated(changedProps: PropertyValues) { protected shouldUpdate(changedProps: PropertyValues) {
super.updated(changedProps);
if (!changedProps.has("hass")) {
return;
}
const oldHass = changedProps.get("hass") as HomeAssistant | undefined; const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
if (oldHass && oldHass.language !== this.hass.language) { const languageChanged =
this._rtl = computeRTL(this.hass); oldHass === undefined || oldHass.language !== this.hass.language;
} return changedProps.has("entries") || languageChanged;
} }
protected firstUpdated(changedProps: PropertyValues) { protected updated(_changedProps: PropertyValues) {
super.firstUpdated(changedProps);
this._rtl = computeRTL(this.hass); this._rtl = computeRTL(this.hass);
} }