I would like to merge several Obserables into one. I use Observable.mergeWith() method. My requirement is to merge inside the loop. The problem is no emissions are sent on subscription. The issue seems to be way I initialize main Observale using Observable<String> observable = Observable.never();
but I did not find the proper way to do it (tried PublishSubject.create();
and Observable.empty();
)
import io.reactivex.Observable;
import io.reactivex.rxjavafx.observables.JavaFxObservable;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class NeverApplication extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Observable<String> observable = Observable.never();
VBox vBox = new VBox();
for (int i = 0; i < 4; i++) {
Button button = new Button("Button " + i);
vBox.getChildren().add(button);
Observable<String> clickedObservale = JavaFxObservable.actionEventsOf(button).map(event -> button.getText());
observable.mergeWith(clickedObservale);
}
stage.setScene(new Scene(vBox));
stage.show();
observable.subscribe(next -> System.out.println(next));
}
}