Skip to content

Commit

Permalink
Better code reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
dfed committed Dec 8, 2023
1 parent fe3fcba commit 0559f6a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Sources/SafeDICore/Models/CombinedScope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ actor CombinedScope {
+ Array<Property>(childPropertyToCombinedScopeMap.keys)
)
.sorted()
forwardedProperties = instantiable
.dependencies
// Instantiated properties will self-resolve.
.filter { $0.source == .forwarded }
.map(\.property)
}

// MARK: Internal
Expand Down Expand Up @@ -91,10 +96,9 @@ actor CombinedScope {
let closureArguments: String
switch property.nonLazyPropertyType {
case .forwardingInstantiator:
let forwardedProperties = instantiable.dependencies.filter { $0.source == .forwarded }
// TODO: Would be better to match types rather than assuming property order for the forwarded properties.
// TODO: Throw error if forwardedProperties has multiple of the same type.
closureArguments = " \(forwardedProperties.map(\.property.label).joined(separator: ", ")) in"
closureArguments = " \(combinedScope.forwardedProperties.map(\..label).joined(separator: ", ")) in"
case .instantiator, .lazy:
closureArguments = ""
case .constant:
Expand Down Expand Up @@ -132,8 +136,9 @@ actor CombinedScope {
private let childPropertyToInstantiableConstant: [Property: Instantiable]
private let childPropertyToCombinedScopeMap: [Property: CombinedScope]
private let receivedProperties: Set<Property>

private let propertiesToFulfill: [Property]
private let forwardedProperties: [Property]

private var resolvedProperties = Set<Property>()
private var generateCodeTask: Task<String, Error>?

Expand Down Expand Up @@ -184,12 +189,6 @@ actor CombinedScope {
|| forwardedProperties.contains(property)
}

private lazy var forwardedProperties = instantiable
.dependencies
// Instantiated properties will self-resolve.
.filter { $0.source == .forwarded }
.map(\.property)

// MARK: SatisfiableProperty

private enum SatisfiableProperty {
Expand Down

0 comments on commit 0559f6a

Please sign in to comment.