From a15ea2af45e4430ffbaff1de53e2f9ab9fd2c8da Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Fri, 7 Jan 2022 23:38:45 -0800 Subject: [PATCH] Remove dset/dlv. Use lodash instead. --- package.json | 2 -- src/components/live.ts | 2 -- src/config-mgmt.ts | 13 ++++--------- src/editor.ts | 4 ++-- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index c4d8646d..8fb94131 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,6 @@ "@material/rtl": "^13.0.0", "custom-card-helpers": "^1.8.0", "dayjs": "^1.10.7", - "dlv": "github:developit/dlv", - "dset": "^3.1.1", "embla-carousel": "^5.0.1", "home-assistant-js-websocket": "^5.11.1", "lit": "^2.0.2", diff --git a/src/components/live.ts b/src/components/live.ts index c86e7a7f..4ecb2b20 100644 --- a/src/components/live.ts +++ b/src/components/live.ts @@ -1,7 +1,5 @@ // TODO different live configs per camera -// TODO replace dset/dlv with lodash // TODO evaluate single override section instead of per-subcomponent -// TODO fix adaptive height in fullscreen // TODO Remove id as a concept for cameras and use an array instead? // TODO Convert menu condition to use overrides // TODO Remove media load event console message diff --git a/src/config-mgmt.ts b/src/config-mgmt.ts index 94d1587c..0dc2562d 100644 --- a/src/config-mgmt.ts +++ b/src/config-mgmt.ts @@ -1,5 +1,4 @@ -import delve from 'dlv'; -import { dset } from 'dset'; +import { get, set } from 'lodash-es'; import { CONF_CAMERAS, CONF_CAMERAS_ARRAY_CAMERA_ENTITY, @@ -36,7 +35,7 @@ export const setConfigValue = ( keys: string | (string | number)[], value: unknown, ): void => { - dset(obj, keys, value); + set(obj, keys, value) }; /** @@ -50,11 +49,7 @@ export const getConfigValue = ( keys: string | (string | number)[], def?: unknown, ): unknown => { - // Need to manually split the key apart to use delve array accesses by number. - if (typeof keys === 'string') { - keys = keys.split('.'); - } - return delve(obj, keys, def); + return get(obj, keys, def); }; /** @@ -172,7 +167,7 @@ export const moveConfigValue = ( * @returns The true config path. */ export const getArrayConfigPath = (path: string, index: number): string => { - return path.replace('#', index.toString()); + return path.replace('#', `[${index.toString()}]`); }; /** diff --git a/src/editor.ts b/src/editor.ts index 050caaa9..48a22b37 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -211,10 +211,10 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor * @returns A localized label. */ protected _getLabel(configPath: string): string { - // Strip out single number path components as they are array indicies. + // Strip out array indices from the path. const path = configPath .split('.') - .filter((e) => isNaN(Number(e))) + .filter((e) => !e.match(/^\[[0-9]+\]$/)) .join('.'); return localize(`config.${path}`); }