Skip to content

Instantly share code, notes, and snippets.

@laiso
Last active April 10, 2017 09:56
Show Gist options
  • Save laiso/26134df7e5ecb5c1ba0693df1084fc49 to your computer and use it in GitHub Desktop.
Save laiso/26134df7e5ecb5c1ba0693df1084fc49 to your computer and use it in GitHub Desktop.
Data Binding for a progress HUD in Swift
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)
// 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