Skip to content

Commit

Permalink
feat: add flag moveAllToComponents
Browse files Browse the repository at this point in the history
  • Loading branch information
aeworxet committed Jan 15, 2024
1 parent 6e4f79a commit 0da5951
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions src/Reporters/moveAllToComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const findAllComponents = (
optimizableComponentGroup: OptimizableComponentGroup
): ReportElement[] => {
const allComponents = optimizableComponentGroup.components
// console.log('allComponents: ', allComponents)
const insideComponentsSection = allComponents.filter(isInComponents)
const outsideComponentsSection = getOutsideComponents(allComponents, insideComponentsSection)

Expand All @@ -21,34 +20,19 @@ const findAllComponents = (
let counter = 1

for (const [index, component] of outsideComponentsSection.entries()) {
for (const compareComponent of outsideComponentsSection.slice(index + 1)) {
if (isEqual(component.component, compareComponent.component, false)) {
const existingResult = resultElements.filter(
(reportElement) => component.path === reportElement.path
)[0]
if (!existingResult) {
const componentName =
component.component.name ||
`${optimizableComponentGroup.type.slice(0, -1)}-${counter++}`
const target = `components.${optimizableComponentGroup.type}.${componentName}`
resultElements.push({
path: component.path,
action: Action.Move,
target,
})
resultElements.push({
path: compareComponent.path,
action: Action.Reuse,
target,
})
} else {
resultElements.push({
path: component.path,
action: Action.Reuse,
target: existingResult.target,
})
}
}
const existingResult = resultElements.filter(
(reportElement) => component.path === reportElement.path
)[0]
if (!existingResult) {
const componentName =
component.component.name ||
`${optimizableComponentGroup.type.slice(0, -1)}-${counter++}`
const target = `components.${optimizableComponentGroup.type}.${componentName}`
resultElements.push({
path: component.path,
action: Action.Move,
target,
})
}
}
debug(
Expand Down

0 comments on commit 0da5951

Please sign in to comment.