Viewer fixes to avoid resetting carousel when not necessary.

This commit is contained in:
Dermot Duffy
2022-01-16 15:53:54 -08:00
parent 6fadc862e3
commit 0e8b40f648
5 changed files with 42 additions and 27 deletions
+13
View File
@@ -2,6 +2,7 @@ import { HassEntity, MessageBase } from 'home-assistant-js-websocket';
import { HomeAssistant, stateIcon } from 'custom-card-helpers';
import { StyleInfo } from 'lit/directives/style-map';
import { ZodSchema, z } from 'zod';
import { isEqual } from 'lodash-es';
import { localize } from './localize/localize.js';
import {
@@ -483,3 +484,15 @@ export function arrayMove(target: unknown[], from: number, to: number): void {
target.splice(from, 1);
target.splice(to, 0, element);
}
/**
* Determine if the contents of the n(ew) and o(ld) values have changed. For use
* in lit web components that may have a value that changes address but not
* contents -- and for which a re-render is expensive/jarring.
* @param n The new value.
* @param o The old value.
* @returns `true` is the contents have changed.
*/
export function contentsChanged(n: unknown, o: unknown): boolean {
return !isEqual(n, o);
}