Handling external delegate #2346
Replies: 2 comments 19 replies
-
Hi @JeromeTonnelierOgury, all external SDK's should be considered dependencies and so should be wrapped in an interface and registered with the dependency management system that comes with the library. You should not hold any reference types in your state because that makes equatability essentially impossible. The dependency interface you create will expose endpoints for the various things you can invoke on We have lots of examples of implementing this kind of dependency in our demos and case studies:
|
Beta Was this translation helpful? Give feedback.
-
If I get it right @mbrandonw, I must do something like this ? struct TCAVideoPlayer {
// sasically transform every delegate method into a @Sendable var
var loaded: @Sendable () -> async Bool
}
extension TCAVideoPlayer: DependencyKey {
static let liveValue: TCAVideoPlayer {
let originalPlayer = VideoStreamer()
return TCAVideoPlayer(
loaded: { //implementation }
}
}
Is that the right direction ? Thanks 🙏 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi again!
I have an external SDK (let's say a VideoStreamer) and I want to handle it from my reducer.
Basically I can load a video and I get the various callbacks from a classic delegate.
I guess my "main" Recuder should have a copy of this VideoStreamer (it's a class, to by reference should be fine), but how can I get back some stuff inside the Reducer from a delegate from the VideoStreamer ?
I initially thought of a Combine object or an async variable, but it seems that many people use an AsyncStream. What is the best approach to handle a delegate ?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions