[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.getDate(this.filterDate, this.filterPeriod, this.filterEntity).then(
this.getData(this.filterDate, this.filterPeriod, this.filterEntity).then(
(logbookEntries) => {
this._setEntries(logbookEntries);
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 (!DATA_CACHE[period]) DATA_CACHE[period] = [];

View File

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