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 has a value() method which returns it's current value
final BehaviorSubject<Boolean> subject = BehaviorSubject.<Boolean>create(false);
final Boolean value = subject.getValue();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With