dimanche 27 août 2023

How do I make ViewModels talk to each other in a Compose Desktop app?

I'm building a Jetpack Compose Deskop app that currently as a draft looks like this:

enter image description here

The 1 and 2 are two ViewModels:

// 1
class FilterViewModel {
    val query = mutableStateOf<String?>(null)
    val timeframe = mutableStateOf("Any")
}

// 2
class GridViewModel {
    val items = mutableListOf("foo", "bar", "baz")
}

I'd like the GridViewModel to update its items when the FilterViewModel changes. How do I do that in this situation? Does Jetpack Compose Deskop have anything to offer here or perhaps there are some more general solutions?

Aucun commentaire:

Enregistrer un commentaire