export function persistedUIValuesEqual(left: unknown, right: unknown): boolean { if (Object.is(left, right)) { return true } if (left instanceof Set || right instanceof Set) { if (!(left instanceof Set) || !(right instanceof Set) || left.size !== right.size) { return false } for (const value of left) { if (!right.has(value)) { return false } } return true } if (Array.isArray(left) || Array.isArray(right)) { if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) { return false } return left.every((value, index) => persistedUIValuesEqual(value, right[index])) } if (left === null || right === null || typeof left !== 'object' || typeof right !== 'object') { return false } const leftRecord = left as Record const rightRecord = right as Record const leftKeys = Object.keys(leftRecord) const rightKeys = Object.keys(rightRecord) if (leftKeys.length !== rightKeys.length) { return false } for (const key of leftKeys) { if ( !Object.prototype.hasOwnProperty.call(rightRecord, key) || !persistedUIValuesEqual(leftRecord[key], rightRecord[key]) ) { return false } } return true }