-
Notifications
You must be signed in to change notification settings - Fork 12
fix(entities-shared) : KM-1029 objectsAreEqual #2056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Preview components from this PR in consuming applicationIn consuming application project install preview versions of shared packages generated by this PR:
|
const deepSort = (obj: Record<string, any>): Record<string, any> => { | ||
if (Array.isArray(obj)) { | ||
return sortBy(obj.map(deepSort), (item: any) => JSON.stringify(item)) | ||
} else if (isPlainObject(obj)) { | ||
const sortedObj: Record<string, any> = {} | ||
Object.keys(obj) | ||
.sort() | ||
.forEach((key) => { | ||
sortedObj[key] = deepSort(obj[key]) | ||
}) | ||
return sortedObj | ||
} else { | ||
return obj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm suspicious about this sort operation, in my understanding performing deep equal might not need a sort operation prior to comparison 🤔 Can we try a non-intrusive way for performing the comparison here? For instance, we compare the key first, if we found unmatched key, then the object is not equal, then compare the value, recursively perform the operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, we can compare the keys first and exit early on any mismatch.
Summary
KM-1029
Make sure
objectsAreEqual
supports comparison of deeply nested objects and arrays.