RxJava Observed with last state

Im starting with RxJava and I would like to create an observable that can save the last state ...

In RxSwift, this will be Variable ( https://github.com/ReactiveX/RxSwift/blob/master/Documentation/GettingStarted.md#variables ), but I could not find the equivalent in RxJava ...

I found a job, but its 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(); } 

RxSwift equivalent is

 private(set) var isGettingCompanies: Variable = Variable(false) 

Can you help me? Thanks

+7
java frp rx-java observable rx-swift
source share
1 answer

BehaviorSubject has a value () method that returns the current value

 final BehaviorSubject<Boolean> subject = BehaviorSubject.<Boolean>create(false); final Boolean value = subject.getValue(); 
+4
source share

All Articles