Use proxy-compare for message bubbles

This commit is contained in:
Fedor Indutny 2022-12-22 16:32:03 -08:00 committed by GitHub
parent f92f81dfd6
commit 55a1c5f6c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 442 additions and 562 deletions

View file

@ -1,17 +1,31 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export function isShallowEqual<Obj extends Record<string, unknown>>(
a: Obj,
b: Obj
): boolean {
export function isShallowEqual(a: unknown, b: unknown): boolean {
if (a === b) {
return true;
}
if (typeof a !== typeof b) {
return false;
}
if (a == null || b == null) {
return false;
}
if (typeof a !== 'object') {
return false;
}
const keys = Object.keys(a);
if (keys.length !== Object.keys(b).length) {
return false;
}
for (const key of keys) {
if (a[key] !== b[key]) {
if (
(a as Record<string | number, unknown>)[key] !==
(b as Record<string | number, unknown>)[key]
) {
return false;
}
}