From e7c89cc3f3e69776c6ad62e62a52f8d2f12a81c1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 14 Apr 2023 09:57:37 +0200 Subject: Allow to update a live with untouched privacy --- shared/core-utils/common/object.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'shared/core-utils') diff --git a/shared/core-utils/common/object.ts b/shared/core-utils/common/object.ts index 7f1f147f4..9780b2594 100644 --- a/shared/core-utils/common/object.ts +++ b/shared/core-utils/common/object.ts @@ -45,10 +45,32 @@ function shallowCopy (o: T): T { return Object.assign(Object.create(Object.getPrototypeOf(o)), o) } +function simpleObjectsDeepEqual (a: any, b: any) { + if (a === b) return true + + if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) { + return false + } + + const keysA = Object.keys(a) + const keysB = Object.keys(b) + + if (keysA.length !== keysB.length) return false + + for (const key of keysA) { + if (!keysB.includes(key)) return false + + if (!simpleObjectsDeepEqual(a[key], b[key])) return false + } + + return true +} + export { pick, omit, getKeys, shallowCopy, - sortObjectComparator + sortObjectComparator, + simpleObjectsDeepEqual } -- cgit v1.2.3