File tree Expand file tree Collapse file tree 4 files changed +42
-1
lines changed Expand file tree Collapse file tree 4 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 55 let property = Property.any ([boolProperty1, boolProperty2, boolProperty3])
66 ```
772 . Fixed Result extensions ambiguity (#733 , kudos to @nekrich )
8+ 1 . Fixed Result extensions ambiguity (#733 , kudos to @nekrich )
9+ 1 . Add ` <~ ` binding operator to ` Signal.Observer ` (#635 , kudos to @Marcocanc )
810
911# 6.0.0
10121 . Dropped support for Swift 4.2 (Xcode 9)
Original file line number Diff line number Diff line change 55</p >
66<br />
77
8- [ ![ Carthage compatible] ( https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat )] ( #carthage ) [ ![ CocoaPods compatible] ( https://img.shields.io/cocoapods/v/ReactiveSwift.svg )] ( #cocoapods ) [ ![ SwiftPM compatible] ( https://img.shields.io/badge/SwiftPM-compatible-orange.svg )] ( #swift-package-manager ) [ ![ GitHub release] ( https://img.shields.io/github/release/ReactiveCocoa/ReactiveSwift.svg )] ( https://github.com/ReactiveCocoa/ReactiveSwift/releases ) ![ Swift 4.2 ] ( https://img.shields.io/badge/Swift-4.2 -orange.svg ) ![ platforms] ( https://img.shields.io/badge/platform-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20Linux-lightgrey.svg )
8+ [ ![ Carthage compatible] ( https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat )] ( #carthage ) [ ![ CocoaPods compatible] ( https://img.shields.io/cocoapods/v/ReactiveSwift.svg )] ( #cocoapods ) [ ![ SwiftPM compatible] ( https://img.shields.io/badge/SwiftPM-compatible-orange.svg )] ( #swift-package-manager ) [ ![ GitHub release] ( https://img.shields.io/github/release/ReactiveCocoa/ReactiveSwift.svg )] ( https://github.com/ReactiveCocoa/ReactiveSwift/releases ) ![ Swift 5.0 ] ( https://img.shields.io/badge/Swift-5.0 -orange.svg ) ![ platforms] ( https://img.shields.io/badge/platform-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20Linux-lightgrey.svg )
99
1010🎉 [ Getting Started] ( #getting-started ) 🚄 [ Release Roadmap] ( #release-roadmap )
1111
Original file line number Diff line number Diff line change @@ -102,6 +102,33 @@ extension BindingTargetProvider {
102102 }
103103}
104104
105+ extension Signal . Observer {
106+ /// Binds a source to a target, updating the target's value to the latest
107+ /// value sent by the source.
108+ ///
109+ /// - note: Only `value` events will be forwarded to the Observer.
110+ /// The binding will automatically terminate when the target is
111+ /// deinitialized, or when the source sends a `completed` event.
112+ ///
113+ /// - parameters:
114+ /// - target: A target to be bond to.
115+ /// - source: A source to bind.
116+ ///
117+ /// - returns: A disposable that can be used to terminate binding before the
118+ /// deinitialization of the target or the source's `completed`
119+ /// event.
120+ @discardableResult
121+ public static func <~
122+ < Source: BindingSource >
123+ ( observer: Signal < Value , Error > . Observer , source: Source ) -> Disposable ?
124+ where Source. Value == Value
125+ {
126+ return source. producer. startWithValues { [ weak observer] in
127+ observer? . send ( value: $0)
128+ }
129+ }
130+ }
131+
105132/// A binding target that can be used with the `<~` operator.
106133public struct BindingTarget < Value> : BindingTargetProvider {
107134 public let lifetime : Lifetime
Original file line number Diff line number Diff line change @@ -201,6 +201,18 @@ class UnidirectionalBindingSpec: QuickSpec {
201201 expect ( value) . toEventually ( equal ( 2 ) )
202202 expect ( mainQueueCounter. value) . toEventually ( equal ( 2 ) )
203203 }
204+
205+ describe ( " observer binding operator " ) {
206+ it ( " should forward values to observer " ) {
207+ let targetPipe = Signal < Int ? , Never > . pipe ( )
208+ let sourcePipe = Signal < Int ? , Never > . pipe ( )
209+ let targetProperty = Property < Int ? > ( initial: nil , then: targetPipe. output)
210+ targetPipe. input <~ sourcePipe. output
211+ expect ( targetProperty. value) . to ( beNil ( ) )
212+ sourcePipe. input. send ( value: 1 )
213+ expect ( targetProperty. value) . to ( equal ( 1 ) )
214+ }
215+ }
204216 }
205217 }
206218}
You can’t perform that action at this time.
0 commit comments