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?>) {
|
public init(_ keyPath: KeyPath<InjectionValues, T?>) {
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.observerRef = ObserverRef()
|
self.observerRef = ObserverRef(
|
||||||
observerRef.id = DIContainer.shared.addObserver(for: keyPath) {
|
id: DIContainer.shared.addObserver(for: keyPath) {
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
StateManager.updateViews()
|
StateManager.updateViews()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class ObserverRef {
|
private final class ObserverRef {
|
||||||
var id: UUID?
|
let id: UUID
|
||||||
deinit {
|
init(id: UUID) { self.id = id }
|
||||||
if let id {
|
deinit { DIContainer.shared.removeObserver(id) }
|
||||||
DIContainer.shared.removeObserver(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue