Last active
April 10, 2017 09:56
-
-
Save laiso/26134df7e5ecb5c1ba0693df1084fc49 to your computer and use it in GitHub Desktop.
Data Binding for a progress HUD in Swift
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
viewModel.showLoadingHUD.asDriver(onErrorJustReturn: false) | |
.drive(onNext: { show in | |
if show { | |
HUD.show(.progress) | |
} else { | |
HUD.hide() | |
} | |
}) | |
.addDisposableTo(disposeBag) | |
// really need | |
viewModel.showLoadingHUD.bindTo(HUD.rx.isShowLoading) | |
.addDisposableTo(disposeBag) |
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
// public | |
let completetion: Observable<Void> | |
// init(:) | |
let showLoadingHUDState = Variable<Bool>(false) | |
showLoadingHUD = showLoadingHUDState.asObservable() | |
completetion = submit.throttle(0.3, scheduler: ConcurrentMainScheduler.instance) | |
.withLatestFrom(Observable.combineLatest(emailS, passwordS)) | |
.do(onNext: { _ in showLoadingHUDState.value = true }) | |
.flatMapLatest { email, password -> Observable<CreateResourceResult> in | |
return api.send(email: email, password: password) | |
} | |
.do(onNext: { _ in showLoadingHUDState.value = true }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment