Last active
April 8, 2019 11:08
-
-
Save hsleedevelop/fe97a4f6569083bca9f16d91689e363b to your computer and use it in GitHub Desktop.
multiple Binding At Once Example
This file contains hidden or 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 binder: (Observable<Bool>) -> Disposable = { obs in | |
return obs.bind(to: self.tableView.rx.printing) | |
} | |
let bindCurry: (Observable<Bool>) -> (Binder<Bool>) -> Observable<Bool> = { obs in | |
return { binder in | |
obs.bind(to: binder).disposed(by: self.disposeBag) | |
return obs | |
} | |
} | |
let bindCurry2: (Observable<Bool>) -> (Binder<Bool>, DisposeBag) -> Observable<Bool> = { obs in | |
return { binder, bag in | |
obs.bind(to: binder).disposed(by: bag) | |
return obs | |
} | |
} | |
Observable.just(true) | |
.bind(to: tableView.rx.printing3, by: self.disposeBag) | |
.bind(to: bindCurry2)(tableView.rx.printing2, self.disposeBag) | |
.bind(to: binder) | |
.disposed(by: disposeBag) | |
extension Reactive where Base: UITableView { | |
var printing: Binder<Bool> { | |
return Binder(self.base) { view, value in | |
print(">>>\(value)") | |
} | |
} | |
var printing2: Binder<Bool> { | |
return Binder(self.base) { view, value in | |
print(">>2>>\(value)") | |
} | |
} | |
var printing3: Binder<Bool> { | |
return Binder(self.base) { view, value in | |
print(">>3>>\(value)") | |
} | |
} | |
} | |
extension ObservableType { | |
func bind(to binder: Binder<Self.E>, by bag: DisposeBag) -> Self { | |
self.bind(to: binder).disposed(by: bag) | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment