Skip to content

Commit

Permalink
docs: add comment for circular reference
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Jan 8, 2024
1 parent e7a7597 commit d1f6082
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/plugin-vue/src/handleHotUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,25 @@ export function isOnlyTemplateChanged(
)
}

function deepEqual(obj1: any, obj2: any, excludeProps: string[] = [], deepParentsOfObj1: any[] = []): boolean {
function deepEqual(
obj1: any,
obj2: any,
excludeProps: string[] = [],
deepParentsOfObj1: any[] = [],
): boolean {
// Check if both objects are of the same type
if (typeof obj1 !== typeof obj2) {
return false
}

// Check if both objects are primitive types or null
if (obj1 == null || obj2 == null || typeof obj1 !== 'object' || deepParentsOfObj1.includes(obj1)) {
// and not a circular reference
if (
obj1 == null ||
obj2 == null ||
typeof obj1 !== 'object' ||
deepParentsOfObj1.includes(obj1)
) {
return obj1 === obj2
}

Expand All @@ -229,7 +240,12 @@ function deepEqual(obj1: any, obj2: any, excludeProps: string[] = [], deepParent
continue
}

if (!deepEqual(obj1[key], obj2[key], excludeProps, [...deepParentsOfObj1, obj1])) {
if (
!deepEqual(obj1[key], obj2[key], excludeProps, [
...deepParentsOfObj1,
obj1,
])
) {
return false
}
}
Expand Down

0 comments on commit d1f6082

Please sign in to comment.