Pass observer ID directly to ObserverRef init
This commit is contained in:
parent
86940f3d7d
commit
7173da4464
1 changed files with 9 additions and 11 deletions
|
|
@ -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) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue