Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Sources/FactoryKit/FactoryKit/Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ extension FactoryModifying {
case .arg, .args, .device, .simulator:
registration.context(context, key: registration.key, factory: factory)
default:
#if DEBUG
registration.context(context, key: registration.key, factory: factory)
#endif
break
}
}
Expand Down
17 changes: 14 additions & 3 deletions Sources/FactoryKit/FactoryKit/Registrations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,21 @@ public struct FactoryRegistration<P,T>: Sendable {
traceNewType = "O" // .onTest, .onDebug, etc.
#endif
current = found.factory
} else if let found = options?.factoryForCurrentContext()?.untypedFactory as? @Sendable (P) -> T {
#if DEBUG
traceNewType = "O" // .onTest, .onDebug, etc. (cross-module)
#endif
current = found
} else if let found = manager.registrations[key] as? TypedFactory<P,T> {
#if DEBUG
traceNewType = "R" // .register {}
#endif
current = found.factory
} else if let found = manager.registrations[key]?.untypedFactory as? @Sendable (P) -> T {
#if DEBUG
traceNewType = "R" // .register {} (cross-module)
#endif
current = found
} else {
#if DEBUG
traceNewType = "F" // Factory { ... }
Expand Down Expand Up @@ -341,14 +351,12 @@ extension FactoryOptions {
}
}
if let contexts = contexts, !contexts.isEmpty {
#if DEBUG
if FactoryContext.current.isPreview, let found = contexts["preview"] {
return found
}
if FactoryContext.current.isTest, let found = contexts["test"] {
return found
}
#endif
if FactoryContext.current.isSimulator, let found = contexts["simulator"] {
return found
}
Expand Down Expand Up @@ -378,8 +386,11 @@ internal struct FactoryDebugInformation {
#endif

// Internal Factory type
internal protocol AnyFactory {}
internal protocol AnyFactory {
var untypedFactory: Any { get }
}

internal struct TypedFactory<P,T>: AnyFactory {
let factory: @Sendable (P) -> T
var untypedFactory: Any { factory }
}
2 changes: 2 additions & 0 deletions Sources/FactoryKit/FactoryKit/Resolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ extension Resolving {
let key = FactoryKey(type: T.self, key: globalResolverKey)
if let factory = manager.registrations[key] as? TypedFactory<Void,T> {
return Factory(FactoryRegistration<Void,T>(key: globalResolverKey, container: self, factory: factory.factory))
} else if let factory = manager.registrations[key]?.untypedFactory as? @Sendable (Void) -> T {
return Factory(FactoryRegistration<Void,T>(key: globalResolverKey, container: self, factory: factory))
}
// otherwise return nil
return nil
Expand Down