mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 15:26:40 +00:00
revert observable to a pre ios 26 implementation
This commit is contained in:
@@ -14,37 +14,25 @@ extension Observable {
|
|||||||
///
|
///
|
||||||
/// - Parameter property: The key path to the property you would like to observe.
|
/// - Parameter property: The key path to the property you would like to observe.
|
||||||
func observe<Value>(_ property: KeyPath<Self, Value>) -> AsyncStream<Value> {
|
func observe<Value>(_ property: KeyPath<Self, Value>) -> AsyncStream<Value> {
|
||||||
if #available(iOS 26, *) {
|
AsyncStream { continuation in
|
||||||
let observations = Observations { self[keyPath: property] }
|
let isActive = Mutex(true)
|
||||||
return AsyncStream { continuation in
|
|
||||||
let task = Task {
|
@Sendable func observe() {
|
||||||
for await value in observations {
|
let value = withObservationTracking {
|
||||||
continuation.yield(value)
|
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.onTermination = { _ in task.cancel() }
|
continuation.yield(value)
|
||||||
}
|
|
||||||
} 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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user