This question is perhaps aimed at the creator of ReactFX, but others are welcome to answer.
I am currently starting to use ReactFX for data sharing and event handling within a JavaFX application. My question is how can a class subscribe to listen to events from two(or more) different EventStreams
. Suppose that in a Controller class
I have a textfield
that may be updated with a new text(String)
, so this class would implement Consumer<String>
. But then you may also want for this textfield
to be updated with a new Integer
(for example) coming from a totally different source, so it would have to implement Consumer<Integer>
, only you can't do that because it already implements Consumer<String>
.
I thought about creating a bundle class with an id field(with an Enum
for example) and an Object field
containing the data, lets name it ReactFXEventBundle
. Only instances of this class will be able to be used as Events
, where the consumer can identify the type of Event by analyzing the id field. Therefore, all Consumer classes would implement Consumer<ReactFXEventBundle>
. Would this be the right approach?