This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class RxStore<Input, Output> { | |
private BehaviorSubject<Input> subject = BehaviorSubject.create(); | |
private Observable<Output> observable; | |
public final Subscription register(Subscriber<Output> subscriber) { | |
if (observable == null) { | |
observable = subject.compose(getTransformer()); | |
} | |
return observable.subscribe(subscriber); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
observableThatShouldNotCompleteOnError | |
.flatMap(e -> obsrevableThatMayThrow(e) | |
.onErrorResumeNext(Observable.empty()) | |
).subscribe() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override public void onNext(DataResponse response) { | |
if (response.isSuccessful()) { | |
displayData(response.getData()); | |
} else { | |
showError(response.getError()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override public void onNext(DataResponse response) { | |
if (response.isSuccessful()) { | |
displayData(response.getData()); | |
} else { | |
showError(response.getError()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<Data> dataStream = RxView.clicks(button) | |
.observeOn(Schedulers.io()) | |
.debounce(2, TimeUnit.SECONDS) | |
.flatMap(new Func1<Void, Observable<Data>>() { | |
@Override | |
public Observable<Data> call(Void aVoid) { | |
Log.d(TAG, "Performing network request..."); | |
return apiEndpoints.getData(); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<Data> dataStream = Observable.just(1) | |
.observeOn(Schedulers.io()) | |
.debounce(2, TimeUnit.SECONDS) | |
.flatMap(new Func1<Integer, Observable<Data>>() { | |
@Override | |
public Observable<Data> call(Integer aVoid) { | |
Log.d(TAG, "Performing network request..."); | |
return apiEndpoints.getData(); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<Data> dataStream = RxView.clicks(button)... //create the stream as before | |
dataStream.subscribe(data -> Log.d(TAG, "View one received the data")); | |
dataStream.subscribe(data -> Log.d(TAG, "View two received the data")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RxView.clicks(button) | |
.observeOn(Schedulers.io()) | |
.debounce(2, TimeUnit.SECONDS) | |
.flatMap(aVoid -> apiEndpoints.getData()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(...); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RxView.clicks(button) | |
.flatMap(new Func1<Void, Observable<Data>>() { | |
@Override | |
public Observable<Data> call(Void aVoid) { | |
return apiEndpoints | |
.getData() | |
.subscribeOn(Schedulers.io()); | |
} | |
}) | |
.observeOn(AndroidSchedulers.mainThread()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<Data> dataStream = RxView.clicks(button) | |
.flatMap(new Func1<Void, Observable<Data>>() { | |
@Override | |
public Observable<Data> call(Void aVoid) { | |
return apiEndpoints.getData(); | |
} | |
}); |