2016-06-04 1 views
1

GUI에서 작업 중이며 버튼을 사용하지 못하게하는 여러 가지 유형의 이벤트가 있습니다. 나는이 두 Observable을 결합하는 몇 가지 방법을 시도했지만 결과가 나오기 전에 Observables가 이벤트를 게시해야한다는 것을 알게되었습니다. 예를 들어,이 코드 :부모님의 모든 변화에 따라 작동하는 RxJava zip

public class Test { 

    public static void main(String[] args) { 
     PublishSubject<Boolean> conditionAStream = PublishSubject.create(); 
     PublishSubject<Boolean> conditionBStream = PublishSubject.create(); 

     conditionAStream 
       .zipWith(conditionBStream, (conditionA, conditionB) -> conditionA && conditionB) 
       .subscribe(result -> System.out.println(result)); 

     conditionAStream.onNext(false); 
     conditionBStream.onNext(false); 
     //Expected output: false 

     conditionAStream.onNext(true); 
     //Expected output: false 

     conditionBStream.onNext(true); 
     //Expected output: true 

     conditionAStream.onNext(false); 
     //Expected output: false 
    } 
} 

하지만 얻을 출력은 다음과 같습니다

false 
true 

모든 변화에 반응하고 "캐시"마지막 결과 있도록 Observables은에 결합 할 수있는 방법이 있습니까 ?

답변

1

combineLatest()을 찾고 있는데, 조합 된 관찰 물이 방출 될 때마다 방출됩니다. 그것은 여전히 ​​각각 적어도 한 번만 방출해야하지만, 조합 된 모든 관측 자료에 .startWith()을 추가하여 초기 방출을 확보 할 수 있습니다.

관련 문제