You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say I have an external device, and only specific devices have a voice recording feature.
enum Hardware {
case foo(Foo)
case foo2(Foo2)
struct Foo { }
struct Foo2 { }
}
struct HardwareAPI {
var recordVoice: @Sendable (Hardware) -> (() async throws -> Void)?
static let live: Self =
.init { hardware in
switch hardware {
case .foo: return { }
case .foo2: return nil
}
}
}
This feature is part of the navigation flow, so it has a specific detail screen. Ideally, I should not be able to initiate this feature without unwrapping the voice record API.
I don't want to handle the optional API in the VoiceRecordFeature reducer. I want to handle it in the parent and pass the unwrapped API to the child reducer if I can unwrap it; if not, the action case should return.
I can hold the API in the reducer state so that I would have to unwrap the API first and then initialize the reducer state to push the feature in the navigation stack. However, this approach requires additional work to conform to Equatable since the API is a closure. I believe this also breaks the current dependency injection approach.
What is the best way to handle optional dependencies?
The real case is much more complex than this. If needed, I can provide a sample project to explain the problem.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Let's say I have an external device, and only specific devices have a voice recording feature.
This feature is part of the navigation flow, so it has a specific detail screen. Ideally, I should not be able to initiate this feature without unwrapping the voice record API.
I don't want to handle the optional API in the VoiceRecordFeature reducer. I want to handle it in the parent and pass the unwrapped API to the child reducer if I can unwrap it; if not, the action case should return.
I can hold the API in the reducer state so that I would have to unwrap the API first and then initialize the reducer state to push the feature in the navigation stack. However, this approach requires additional work to conform to Equatable since the API is a closure. I believe this also breaks the current dependency injection approach.
What is the best way to handle optional dependencies?
The real case is much more complex than this. If needed, I can provide a sample project to explain the problem.
Beta Was this translation helpful? Give feedback.
All reactions