-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
DRYCode duplication / DRY violationCode duplication / DRY violationenhancementNew feature or requestNew feature or request
Description
Problem
ComponentDefinition has 10 stored properties. When code needs to create a modified copy with a different installAction, it must manually reconstruct the entire struct:
ComponentDefinition(
id: component.id,
displayName: component.displayName,
description: component.description,
type: component.type,
packIdentifier: component.packIdentifier,
dependencies: component.dependencies,
isRequired: component.isRequired,
hookRegistration: component.hookRegistration,
installAction: .copyPackFile(source: source, destination: newDestination, fileType: fileType),
supplementaryChecks: component.supplementaryChecks
)If ComponentDefinition gains a new stored property, this code silently omits it (the custom init has defaults for some parameters). This is fragile.
Proposed Solution
Add a withInstallAction(_:) convenience method:
extension ComponentDefinition {
func withInstallAction(_ action: ComponentInstallAction) -> ComponentDefinition {
ComponentDefinition(
id: id, displayName: displayName, description: description,
type: type, packIdentifier: packIdentifier,
dependencies: dependencies, isRequired: isRequired,
hookRegistration: hookRegistration, installAction: action,
supplementaryChecks: supplementaryChecks
)
}
}This centralizes the copy logic so new properties only need to be added in one place.
Current usage
Sources/mcs/Install/DestinationCollisionResolver.swift(lines 62-73)
References
Sources/mcs/TechPack/Component.swift—ComponentDefinitionstruct
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
DRYCode duplication / DRY violationCode duplication / DRY violationenhancementNew feature or requestNew feature or request