mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Use iOS 26 Observation for Unit and Preview tests. (#5797)
* use observation in unit and preview tests instead of the async stream * use a parsing approach that is independent of the sourcery annotation * Fix observation deferred fulfillments not receiving the initial value Observation's observe only emits transitions, not the value present at subscription time. Drop the leading initial value from the affected transitionValues sequences and assert it directly with #expect instead. * improved docs
This commit is contained in:
@@ -7,13 +7,25 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Observation
|
||||
import Synchronization
|
||||
|
||||
extension Observable {
|
||||
/// Creates an async stream for the specified property on this object. We probably won't need this once SE-0475 is available:
|
||||
/// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0475-observed.md
|
||||
/// A convenience wrapper around the `Observations` sequence (SE-0475).
|
||||
///
|
||||
/// - Parameter property: The key path to the property you would like to observe.
|
||||
@available(iOS 26.0, *)
|
||||
@MainActor func observe<Value: Sendable>(_ property: KeyPath<Self, Value>) -> Observations<Value, Never> {
|
||||
Observations { self[keyPath: property] }
|
||||
}
|
||||
|
||||
/// Creates an async stream for the specified property on this object.
|
||||
///
|
||||
/// iOS 18 fallback for ``observe(_:)``. Remove once the minimum deployment target reaches iOS 26.
|
||||
///
|
||||
/// - Parameter property: The key path to the property you would like to observe.
|
||||
@available(iOS, deprecated: 26.0, message: "Use observe(_:) which is backed by the Observations sequence.")
|
||||
@_disfavoredOverload
|
||||
@MainActor func observe<Value: Sendable>(_ property: KeyPath<Self, Value>) -> AsyncStream<Value> {
|
||||
let (stream, continuation) = AsyncStream<Value>.makeStream()
|
||||
let (changeSignals, changeSignaller) = AsyncStream<Void>.makeStream()
|
||||
|
||||
Reference in New Issue
Block a user