more fixes and preview tests updated

This commit is contained in:
Mauro Romito
2025-09-11 19:03:29 +02:00
committed by Stefan Ceriu
parent 89a8c2850a
commit 78c3ea9696
1007 changed files with 2042 additions and 2018 deletions
@@ -14,25 +14,37 @@ extension Observable {
///
/// - Parameter property: The key path to the property you would like to observe.
func observe<Value>(_ property: KeyPath<Self, Value>) -> AsyncStream<Value> {
AsyncStream { continuation in
let isActive = Mutex(true)
@Sendable func observe() {
let value = withObservationTracking {
self[keyPath: property]
} onChange: {
// Handle the update on the next run loop as this is willSet not didSet.
DispatchQueue.main.async {
guard isActive.withLock({ $0 }) else { return }
observe()
if #available(iOS 26, *) {
let observations = Observations { self[keyPath: property] }
return AsyncStream { continuation in
let task = Task {
for await value in observations {
continuation.yield(value)
}
}
continuation.yield(value)
continuation.onTermination = { _ in task.cancel() }
}
} else {
return AsyncStream { continuation in
let isActive = Mutex(true)
@Sendable func observe() {
let value = withObservationTracking {
self[keyPath: property]
} onChange: {
// Handle the update on the next run loop as this is willSet not didSet.
DispatchQueue.main.async {
guard isActive.withLock({ $0 }) else { return }
observe()
}
}
continuation.yield(value)
}
continuation.onTermination = { _ in isActive.withLock { $0 = false } }
observe()
}
continuation.onTermination = { _ in isActive.withLock { $0 = false } }
observe()
}
}
}