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