Merge pull request #48 from TouchInstinct/bind_fix

Binding simplified to not observe on something if there are no callbacks
This commit is contained in:
Gavriil 2017-03-03 15:29:20 +03:00 committed by GitHub
commit e4808c1648
1 changed files with 8 additions and 4 deletions

View File

@ -158,11 +158,15 @@ public class BaseLifecycleBindable implements LifecycleBindable {
@NonNull final Action1<T> onNextAction,
@NonNull final Action1<Throwable> onErrorAction,
@NonNull final Action0 onCompletedAction) {
final Observable<T> actualObservable;
if (onNextAction == Actions.empty() && onNextAction == Actions.empty() && onNextAction == Actions.empty()) {
actualObservable = observable.doOnCompleted(onCompletedAction);
} else {
actualObservable = observable.observeOn(AndroidSchedulers.mainThread()).doOnCompleted(onCompletedAction);
}
return isCreatedSubject.first()
.switchMap(created -> created
? observable.observeOn(AndroidSchedulers.mainThread()).doOnCompleted(onCompletedAction)
: Observable.empty())
//TODO: basically takeUntil is calling completed so investigate observable = ***.first() behavior and doOnCompleted also
.switchMap(created -> created ? actualObservable : Observable.empty())
.takeUntil(conditionSubject.filter(condition -> condition))
.subscribe(onNextAction, throwable -> {
final boolean isRxError = throwable instanceof OnErrorThrowable;