Update Injected state mechanism

This commit is contained in:
Brendan Szymanski 2026-06-14 19:29:01 -04:00
parent 428eb32be1
commit 91faf3c0f4
2 changed files with 3 additions and 4 deletions

View file

@ -1,3 +1,4 @@
import Adwaita
import Foundation import Foundation
public final class DIContainer: @unchecked Sendable { public final class DIContainer: @unchecked Sendable {
@ -55,7 +56,7 @@ public final class DIContainer: @unchecked Sendable {
private func notifyObservers(for keyPath: AnyKeyPath) { private func notifyObservers(for keyPath: AnyKeyPath) {
let handlers: [@Sendable () -> Void] = lock.withLock { let handlers: [@Sendable () -> Void] = lock.withLock {
Array(observers[keyPath]?.values ?? []) Array((observers[keyPath] ?? [:]).values)
} }
handlers.forEach { $0() } handlers.forEach { $0() }
} }

View file

@ -15,10 +15,8 @@ public struct Injected<T> {
self.keyPath = keyPath self.keyPath = keyPath
self.observerRef = ObserverRef( self.observerRef = ObserverRef(
id: DIContainer.shared.addObserver(for: keyPath) { id: DIContainer.shared.addObserver(for: keyPath) {
Task { @MainActor in
StateManager.updateViews() StateManager.updateViews()
} }
}
) )
} }
} }