Hi, What would be the best or recommended way for ...
# tornadofx
Hi, What would be the best or recommended way for the communication between different ViewModels? Imagine having a text field, a table and a text area. When I enter some name into the text field and press enter, a new file with this name should be created, added to the list, and used by the text area to compose the text, which is automatically saved in the background whenever the user stops typing. Also, when a file is selected in the table its name should be inserted into the text field and the user can edit the file via the text area. Currently I have three ViewModels, one for each component. Table and text area communicate via a shared ViewModel, similar to the example shown in the tornadofx guide. But I'm not sure how to communicate e.g. the creation of a file to the other components. I was also thinking about using the event bus as this is something that I can wrap my head around. Another possibility is to use only a single ViewModel for all views. Any best practice tips for this?
I think this is a good use case for a controller. You can put an ObservableList in your controller and render the list from your controller in your table, then have the text field trigger something in the controller which adds to the list.