Pass observer ID directly to ObserverRef init

This commit is contained in:
Brendan Szymanski 2026-06-14 16:21:44 -04:00
parent 86940f3d7d
commit 7173da4464

View file

@ -13,20 +13,18 @@ public struct Injected<T> {
public init(_ keyPath: KeyPath<InjectionValues, T?>) {
self.keyPath = keyPath
self.observerRef = ObserverRef()
observerRef.id = DIContainer.shared.addObserver(for: keyPath) {
self.observerRef = ObserverRef(
id: DIContainer.shared.addObserver(for: keyPath) {
Task { @MainActor in
StateManager.updateViews()
}
}
)
}
}
private final class ObserverRef {
var id: UUID?
deinit {
if let id {
DIContainer.shared.removeObserver(id)
}
}
let id: UUID
init(id: UUID) { self.id = id }
deinit { DIContainer.shared.removeObserver(id) }
}