Some performance optimizations

This commit is contained in:
Jérôme Wiedemann 2020-11-05 02:10:04 +00:00
parent 590247f791
commit 04737e0f46
3 changed files with 12 additions and 5 deletions

View File

@ -59,6 +59,7 @@
"@ctrl/tinycolor": "^2.6.1",
"@material/mwc-ripple": "^0.15.0",
"custom-card-helpers": "^1.6.5",
"fast-copy": "^2.1.0",
"home-assistant-js-websocket": "^5.1.0",
"lit-element": "^2.3.0",
"lit-html": "^1.2.0"

View File

@ -55,7 +55,9 @@ import {
} from './helpers';
import { styles } from './styles';
import { myComputeStateDisplay } from './compute_state_display';
import copy from 'fast-copy';
import * as pjson from '../package.json';
import { deepEqual } from './deep-equal';
let helpers = (window as any).cardHelpers;
const helperPromise = new Promise(async resolve => {
@ -308,7 +310,7 @@ class ButtonCard extends LitElement {
}
private _objectEvalTemplate(state: HassEntity | undefined, obj: any | undefined): any {
const objClone = JSON.parse(JSON.stringify(obj));
const objClone = copy(obj);
return this._getTemplateOrValue(state, objClone);
}
@ -616,11 +618,10 @@ class ButtonCard extends LitElement {
'grid-area': key,
};
let thing;
const stringConfig = JSON.stringify(cards[key]);
if (this._cardsConfig[key] !== stringConfig) {
if (!deepEqual(this._cardsConfig[key], cards[key])) {
thing = this._createCard(cards[key]);
this._cards[key] = thing;
this._cardsConfig[key] = stringConfig;
this._cardsConfig[key] = copy(cards[key]);
} else {
thing = this._cards[key];
}
@ -1021,7 +1022,7 @@ class ButtonCard extends LitElement {
if (this._config.entity && !this._entities.includes(this._config.entity)) this._entities.push(this._config.entity);
this._expandTriggerGroups();
const rxp = new RegExp('\\[\\[\\[.*\\]\\]\\]', 'gm');
const rxp = new RegExp('\\[\\[\\[.*\\]\\]\\]', 'm');
this._hasTemplate = this._config.triggers_update === 'all' && jsonConfig.match(rxp) ? true : false;
if (!this._initial_setup_complete) {
this._initConnected();

View File

@ -2202,6 +2202,11 @@ extsprintf@^1.2.0:
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"
integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8=
fast-copy@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fast-copy/-/fast-copy-2.1.0.tgz#99c1b842aee063f8212d6f749080c196a822b293"
integrity sha512-j4VxAVJsu9NHveYrIj0+nJxXe2lOlibKTlyy0jH8DBwcuV6QyXTy0zTqZhmMKo7EYvuaUk/BFj/o6NU6grE5ag==
fast-deep-equal@^3.1.1:
version "3.1.3"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"