<@UBNH28AHZ> I initiate the Model actions from my ...
# tornadofx
c
@nate I initiate the Model actions from my ViewModel. Sometimes, I'll wrap these in a Task and have the ViewModel expose Task-related properties like progress and running. Because that's where I'm working with the Task, I sometimes facade in the ViewModel, calling two Model functions so that I can slip in an intermediate updateProgress() between them I also have left the progress in an indeterminate state (running=true) while waiting on an event coming from the model. In this case, I initiate the model call which is async from the ViewModel. When the model finishes, it posts an event for interested parties. Receiving this event clears a running/progress flag and prompts the ViewModel to call into the model -- values now saved off -- to retrieve the data.
n
@carlw thank you! just a quick follow-up, I understand what you have said about initiating model actions from the view model, and thats great. However, I was more wondering about listeners for user actions, and from an architectural stand point, if instantiating a control in a viewModel is correct?
Copy code
class ProjectHomeViewModel: ViewModel() {
    private var projectUseCase = GetProjectsUseCase(Injector.projectDao)
    val items = FXCollections.observableArrayList<ProjectCard>()!!
    init {
        getProjects()
    }

    private fun getProjects() {
        projectUseCase.getProjects().subscribe {
            items.setAll(
                    it.map{
                        ProjectCard(it).apply{
                            loadProjectButton.action{

                            }
                        }
                    }
            )
        }
    }
}
i just put the viewModel here again so you wouldn't have to scroll for it
c
i wouldn't register a listener for a particular control in the viewmodel. (i'd keep it in the view)
n
ok cool. that's what made the most sense, thank you