RxJava Observable with last state
I'm starting with RxJava, and I would like to create an observable that can save the last state…
In RxSwift, that would be Variable (https://github.com/ReactiveX/RxSwift/blob/master/Documentation/GettingStarted.md#variables), but I can't found an equivalente in RxJava…
I found a work around but it's a lot of boiler plate code
private boolean isGettingCompanies = false;
public boolean isGettingCompanies() {
return isGettingCompanies;
}
private void setIsGettingCompanies(boolean isGettingCompanies) {
this.isGettingCompanies = isGettingCompanies;
isGettingCompaniesPublishSubject.onNext(isGettingCompanies);
}
private final PublishSubject<Boolean> isGettingCompaniesPublishSubject = PublishSubject.create();
public Observable<Boolean> isGettingCompaniesPublishSubject() {
return isGettingCompaniesPublishSubject.asObservable();
}
the RxSwift equivalent is this
private(set) var isGettingCompanies: Variable = Variable(false)
Can you help me please? Thanks
BehaviorSubject有一个返回当前值的value()方法
final BehaviorSubject<Boolean> subject = BehaviorSubject.<Boolean>create(false);
final Boolean value = subject.getValue();
链接地址: http://www.djcxy.com/p/91296.html
下一篇: RxJava可观察到最后一个状态