Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxSwift Observable.empty() is calling onNext

detect when reached tableview bottom if not bottom return Observable.empty() if tableview is bottom return Observable.just(())

as i Know is Observable.empty() is not calling onNext

but empty() or just() calling onNext

tableView.rx.contentOffset
            .map {
                self.isNearTheBottomEdge(contentOffset: $0, self.tableView) && self.postModel.isLoadingComplete.value
                    ? Observable.just(())
                    : Observable.empty()
            }
            .throttle(3, scheduler: MainScheduler.instance)

            .subscribe(onNext: {
                print("reached bottom")
                self.postModel.nextPage.onNext(())
            },onCompleted: {
                print("complete")
            }
            )
            .disposed(by: disposeBag)

return Observable.empty() in debug but always print("reached bottom")

like image 287
oijafoijf asnjksdjn Avatar asked Nov 07 '22 19:11

oijafoijf asnjksdjn


1 Answers

If you want to have subscribe(onNext) to be not called on Observable.empty(), just change .map{} to .flatMap{}

tableView.rx.contentOffset
            .flatMap {
                self.isNearTheBottomEdge(contentOffset: $0, self.tableView) && self.postModel.isLoadingComplete.value
                    ? Observable.just(())
                    : Observable.empty()
            }

Here you can read about difference between map vs flatMap

like image 163
kamwysoc Avatar answered Nov 14 '22 23:11

kamwysoc