RxJava: composed ObservableTransformer not executed

[ rxjava 2.1.0 ] Hi I just finish watching video about managing state by Jake Wharton. I got a problem though,

    fun loadFirstPage(): ObservableTransformer<LoadFirstPageAction, MainResult> {
        return ObservableTransformer {
            actionStream -> actionStream.flatMap { _ 
                    -> mainModel.getNews("", "10") // <-- whats wrong with you! took 
                                                   // 1 day of my life
                .map { data -> MainResult.success(data) }
                .onErrorReturn { error -> MainResult.failure(error.message ?: "Unknown error") }
                .observeOn(AndroidSchedulers.mainThread())
                .startWith { MainResult.loading()} }
        }
    }

    fun loadNextPage(): ObservableTransformer<LoadNextPageAction, MainResult> {
        ...
    }

    fun actionToResultTransformer(): ObservableTransformer<MainAction, MainResult> {
        return ObservableTransformer {
            actionStream -> actionStream.publish { shared -> Observable.merge(
                shared.ofType(LoadFirstPageAction::class.java).compose(loadFirstPage()),
                shared.ofType(LoadNextPageAction::class.java).compose(loadNextPage())) }
        }
    }

When firing a LoadFirstPageAction, loadFirstPage() gets executed but the observable is not starting. mainModel.getNews("", "10") is a retrofit api.

I know this post is a nono on the guidelines, but I cant find the same issue in the internet.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 28 (11 by maintainers)

Most upvoted comments

I know what’s wrong:

.startWith ( MainResult.loading() )

By using curly braces with startWith, you actually created a no-op Observable instead of specifying a constant initial value. With the changes above, the app works for me.