Last active
December 25, 2018 17:12
-
-
Save vaderdan/4ef62152f62d7c8b82fd4dd09982899e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Two way binding operator between control property and relay, that's all it takes. | |
infix operator <-> : DefaultPrecedence | |
func <-> <T>(property: ControlProperty<T>, relay: BehaviorRelay<T>) -> Disposable { | |
let bindToUIDisposable = relay.bind(to: property) | |
let bindToRelay = property | |
.subscribe(onNext: { n in | |
relay.accept(n) | |
}, onCompleted: { | |
bindToUIDisposable.dispose() | |
}) | |
return Disposables.create(bindToUIDisposable, bindToRelay) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment