Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let headerRefreshTrigger = PublishSubject<Void>()
let retryRefreshTrigger = PublishSubject<Void>()
let refresh = Observable.of(Observable.just(()), headerRefreshTrigger, retryRefreshTrigger.mapToVoid()).merge()
let input = ViewModel.Input(headerRefresh: refresh)
//triggered when retry button tapped
xbutton?.rx.tap.asDriver().drive(onNext: { [weak self] (_) in
self?.retryRefreshTrigger.onNext(())
}).disposed(by: rx.disposeBag)
// Monitor tap action
retryRefreshTrigger.subscribe {[weak self] _ in
print("retryRefreshTrigger")
}.disposed(by: rx.disposeBag)
//
ViewModel
struct Input {
let headerRefresh: Observable<Void>
}
//Perform Network request
input.headerRefresh.flatMap({ [weak self] () ->
Observable<[CellViewModel]> in
guard let self = self else { return Observable.just([]) }
self.page = 1
return self.request()
.trackActivity(self.headerLoading)
})
.subscribe(onNext: { (items) in
elements.accept(items)
}).disposed(by: rx.disposeBag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment