My view model has a computed property - it forward...
# compose
r
My view model has a computed property - it forwards to an underlying model that does not know about the
MutableState
type. Is there a way to signal Compose when this computed property has changed, without keeping a separate copy of the data in my view model as a
MutableState
? (In SwiftUI I do this with
objectWillChange.send()
)
d
Can you give an example of how the data is being forwarded? A small code example perhaps?
z
You could publish the property as a
StateFlow
, but why don’t you want to store a copy of the computed value? That value has to be in memory somewhere, and it would be a lot simpler to just publish the property via a
derivedStateOf
from your view model.
r
I have a property on my viewmodel (for a settings screen) that looks like this:
Copy code
var isPreloadingImages: Boolean
    get() = PreferencesDB.shared.isPreloadingDetailsPageImages
    set(newValue) { PreferencesDB.shared.isPreloadingDetailsPageImages = newValue }
I feel like I should be able to use model classes like
PreferencesDB
without having to edit them to make them Compose-aware, with things like
MutableState
.