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
let textFull = BehaviorRelay<String?>(value: nil) | |
let textFirst = BehaviorRelay<String?>(value: nil) | |
let textSecond = BehaviorRelay<String?>(value: nil) | |
typealias ItemType = (current: String, previous: String) | |
Observable.combineLatest(textFirst.map({ $0 ?? "" }).currentAndPrevious(), textSecond.map({ $0 ?? "" }).currentAndPrevious(), textFull.map({ $0 ?? "" }).currentAndPrevious()) | |
.filter({ (first: ItemType, second: ItemType, full: ItemType) -> Bool in | |
return "\(first.current) \(second.current)" != full.current && "\(first.current)" != full.current |
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
let textFirst = BehaviorRelay<String?>(value: nil) | |
let textSecond = BehaviorRelay<String?>(value: nil) | |
(textSecond <-> textFirst).disposed(by: disposeBag) |
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
let bindToRelay = property | |
.subscribe(onNext: { n in | |
relay.accept(n) | |
}, onCompleted: { | |
bindToUIDisposable.dispose() | |
}) |
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
let bindToUIDisposable = relay.bind(to: property) |
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() |
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
import RxBiBinding | |
let disposeBag = DisposeBag() | |
var textFieldFirst = UITextField() | |
var textFieldSecond = UITextField() | |
(textFieldFirst.rx.text <-> textFieldSecond.rx.text).disposed(by: disposeBag) |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |