Skip to content Skip to sidebar Skip to footer

Implementing Repository Pattern With Rxjava

I'm trying to figure out a better way to achieve something like repository pattern in RxJava in Android. Here's what I have so far: (took some code from here) public Subscription g

Solution 1:

Thanks to akarnokd pointing me out to this article by Dan Lew.

My final code:

public Observable<Data> getData(boolean refresh) {
    Observable<Data> obs = Observable.concat(getCache(), requestNetwork());
    if(!refresh) {
        obs = obs.first(data -> data != null);
    }
    return obs;
}

Post a Comment for "Implementing Repository Pattern With Rxjava"