Hi. I need some advice for MVVM: I have an applica...
# tornadofx
m
Hi. I need some advice for MVVM: I have an application where a user can input simple notes which are then shown as a list. A note (model) consists of a timestamp, the content and a list of hashtags. I have two views, the input (text area) and the note list. Via the input the user can insert text, with hashtags being part of it. So to create a note this text needs to be parsed. What could be the view model for the input and the list? Currently I have this:
Copy code
class NoteListViewModel : ViewModel() {
    val notes: ObservableList<NoteViewModel> = observableListOf()
}

class NoteViewModel : ItemViewModel<Note>() {
    val timestamp = bind(Note::timestamp)
    val contentText = bind(Note::contentText)
    val hashtags = bind(Note::hashtags)

    fun parse(input: String) {

    }
}

class Note(timestamp: Long = 0,
           contentText: String = "",
           hashtags: ObservableList<String> = observableListOf()) {
    ...
}
The idea is to let the user input the text and then call
parse()
to extract the hashtags. The
NoteViewModel
is injected into the input view, the
NoteListViewModel
into the list view. Still I don't know how to connect both, maybe also inject the
NoteViewModel
into the list view and rebind it when the user selects a note from the list to edit it? How would I add a new note to the list of notes?
👍 1