Use lodash cloneDeep and generate facade chunk.
This commit is contained in:
+6
-1
@@ -65,7 +65,12 @@ const plugins = [
|
|||||||
*/
|
*/
|
||||||
const config = {
|
const config = {
|
||||||
input: 'src/card.ts',
|
input: 'src/card.ts',
|
||||||
preserveEntrySignatures: false,
|
// Specifically want a facade created as HACS will attach a hacstag
|
||||||
|
// queryparameter to the resource. Without a facade when chunks re-import the
|
||||||
|
// card chunk, they'll refer to a 'different' copy of the card chunk without
|
||||||
|
// the hacstag, causing a re-download of the same content and functionality
|
||||||
|
// problems.
|
||||||
|
preserveEntrySignatures: 'strict',
|
||||||
output: {
|
output: {
|
||||||
entryFileNames: 'frigate-hass-card.js',
|
entryFileNames: 'frigate-hass-card.js',
|
||||||
dir: 'dist',
|
dir: 'dist',
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import type {
|
|||||||
} from './types';
|
} from './types';
|
||||||
import { HassEntities } from 'home-assistant-js-websocket';
|
import { HassEntities } from 'home-assistant-js-websocket';
|
||||||
import merge from 'lodash-es/merge';
|
import merge from 'lodash-es/merge';
|
||||||
|
import { copyConfig } from './config-mgmt';
|
||||||
|
|
||||||
export interface ConditionState {
|
export interface ConditionState {
|
||||||
view?: string;
|
view?: string;
|
||||||
@@ -109,7 +110,7 @@ export function getOverriddenConfig(
|
|||||||
overrides: Readonly<RawOverrides> | undefined,
|
overrides: Readonly<RawOverrides> | undefined,
|
||||||
conditionState?: Readonly<ConditionState>,
|
conditionState?: Readonly<ConditionState>,
|
||||||
): RawFrigateCardConfig {
|
): RawFrigateCardConfig {
|
||||||
const output = structuredClone(config);
|
const output = copyConfig(config);
|
||||||
let overridden = false;
|
let overridden = false;
|
||||||
if (overrides) {
|
if (overrides) {
|
||||||
for (const override of overrides) {
|
for (const override of overrides) {
|
||||||
|
|||||||
+4
-4
@@ -1,3 +1,4 @@
|
|||||||
|
import cloneDeep from 'lodash-es/cloneDeep'
|
||||||
import get from 'lodash-es/get';
|
import get from 'lodash-es/get';
|
||||||
import isEqual from 'lodash-es/isEqual';
|
import isEqual from 'lodash-es/isEqual';
|
||||||
import set from 'lodash-es/set';
|
import set from 'lodash-es/set';
|
||||||
@@ -107,8 +108,7 @@ export const upgradeConfig = function (obj: RawFrigateCardConfig): boolean {
|
|||||||
* @returns `true` if the configuration is upgradeable.
|
* @returns `true` if the configuration is upgradeable.
|
||||||
*/
|
*/
|
||||||
export const isConfigUpgradeable = function (obj: RawFrigateCardConfig): boolean {
|
export const isConfigUpgradeable = function (obj: RawFrigateCardConfig): boolean {
|
||||||
const newObj = structuredClone(obj);
|
return upgradeConfig(copyConfig(obj));
|
||||||
return upgradeConfig(newObj);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,8 +138,8 @@ export const trimConfig = function (obj: RawFrigateCardConfig): boolean {
|
|||||||
* @param obj Configuration to copy.
|
* @param obj Configuration to copy.
|
||||||
* @returns A new deeply-copied configuration.
|
* @returns A new deeply-copied configuration.
|
||||||
*/
|
*/
|
||||||
export const copyConfig = function (obj: RawFrigateCardConfig): RawFrigateCardConfig {
|
export const copyConfig = <T>(obj: T): T => {
|
||||||
return structuredClone(obj);
|
return cloneDeep(obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-2
@@ -252,7 +252,7 @@ const options: EditorOptions = {
|
|||||||
export class FrigateCardEditor extends LitElement implements LovelaceCardEditor {
|
export class FrigateCardEditor extends LitElement implements LovelaceCardEditor {
|
||||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||||
@state() protected _config?: RawFrigateCardConfig;
|
@state() protected _config?: RawFrigateCardConfig;
|
||||||
@state() protected _defaults = structuredClone(frigateCardConfigDefaults);
|
@state() protected _defaults = copyConfig(frigateCardConfigDefaults);
|
||||||
|
|
||||||
protected _initialized = false;
|
protected _initialized = false;
|
||||||
protected _configUpgradeable = false;
|
protected _configUpgradeable = false;
|
||||||
@@ -481,7 +481,7 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
|
||||||
if (unvalidatedProfile === 'high' || unvalidatedProfile === 'low') {
|
if (unvalidatedProfile === 'high' || unvalidatedProfile === 'low') {
|
||||||
const defaults = structuredClone(frigateCardConfigDefaults);
|
const defaults = copyConfig(frigateCardConfigDefaults);
|
||||||
if (unvalidatedProfile === 'low') {
|
if (unvalidatedProfile === 'low') {
|
||||||
setLowPerformanceProfile(this._config, defaults);
|
setLowPerformanceProfile(this._config, defaults);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user