Skip to content

Commit 69f4ca9

Browse files
committed
refactor: code formatting
1 parent f252064 commit 69f4ca9

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

src/utils.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -259,52 +259,52 @@ export function aggregateDiffsWithRollup(obj: any, diffProperty: any, aggregated
259259
const visited = new Set<any>()
260260

261261
function _aggregateDiffsWithRollup(obj: any): Set<Diff> | undefined {
262-
if (obj === null || typeof obj !== 'object' ) {
263-
return undefined
264-
}
262+
if (!isObject(obj)) {
263+
return undefined
264+
}
265265

266-
if (visited.has(obj)) {
267-
return obj[aggregatedDiffProperty]
268-
}
266+
if (visited.has(obj)) {
267+
return obj[aggregatedDiffProperty] as Set<Diff> | undefined
268+
}
269+
270+
visited.add(obj)
269271

270-
visited.add(obj)
271-
272-
// Process all children and collect their diffs
273-
const childrenDiffs = new Array<Set<Diff>>()
274-
if (Array.isArray(obj)) {
275-
for (const item of obj) {
276-
const childDiffs = _aggregateDiffsWithRollup(item)
277-
childDiffs && childDiffs.size > 0 && childrenDiffs.push(childDiffs)
278-
}
279-
} else {
280-
for (const [_, value] of Object.entries(obj)) {
281-
const childDiffs = _aggregateDiffsWithRollup(value)
282-
childDiffs && childDiffs.size > 0 && childrenDiffs.push(childDiffs)
283-
}
272+
// Process all children and collect their diffs
273+
const childrenDiffs = new Array<Set<Diff>>()
274+
if (Array.isArray(obj)) {
275+
for (const item of obj) {
276+
const childDiffs = _aggregateDiffsWithRollup(item)
277+
childDiffs && childDiffs.size > 0 && childrenDiffs.push(childDiffs)
278+
}
279+
} else {
280+
for (const [_, value] of Object.entries(obj)) {
281+
const childDiffs = _aggregateDiffsWithRollup(value)
282+
childDiffs && childDiffs.size > 0 && childrenDiffs.push(childDiffs)
284283
}
284+
}
285+
286+
const hasOwnDiffs = diffProperty in obj
285287

286-
const hasOwnDiffs = diffProperty in obj
287-
288-
if (hasOwnDiffs || childrenDiffs.length > 1) {
289-
// obj aggregated diffs are different from children diffs
290-
const aggregatedDiffs = new Set<Diff>()
291-
for (const childDiffs of childrenDiffs) {
292-
childDiffs.forEach(diff => aggregatedDiffs.add(diff))
293-
}
294-
const diffs = obj[diffProperty]
295-
for (const key in diffs) {
296-
aggregatedDiffs.add(diffs[key])
297-
}
298-
// Store the aggregated diffs in the object
299-
obj[aggregatedDiffProperty] = aggregatedDiffs
300-
}else if (childrenDiffs.length === 1) {
301-
// could reuse a child diffs if there is only one
302-
[obj[aggregatedDiffProperty]] = childrenDiffs
303-
}else{
304-
// no diffs- no aggregated diffs get assigned
288+
if (hasOwnDiffs || childrenDiffs.length > 1) {
289+
// obj aggregated diffs are different from children diffs
290+
const aggregatedDiffs = new Set<Diff>()
291+
for (const childDiffs of childrenDiffs) {
292+
childDiffs.forEach(diff => aggregatedDiffs.add(diff))
305293
}
294+
const diffs = obj[diffProperty] as Record<string, Diff>
295+
for (const key in diffs) {
296+
aggregatedDiffs.add(diffs[key])
297+
}
298+
// Store the aggregated diffs in the object
299+
obj[aggregatedDiffProperty] = aggregatedDiffs
300+
} else if (childrenDiffs.length === 1) {
301+
// could reuse a child diffs if there is only one
302+
[obj[aggregatedDiffProperty]] = childrenDiffs
303+
} else {
304+
// no diffs- no aggregated diffs get assigned
305+
}
306306

307-
return obj[aggregatedDiffProperty]
307+
return obj[aggregatedDiffProperty] as Set<Diff> | undefined
308308
}
309309

310310
return _aggregateDiffsWithRollup(obj)

0 commit comments

Comments
 (0)