ubu
09/20/2018, 9:21 AMMVVM architecture when dealing with MapView.
Coming from MVP pattern, I sometimes don't know how to command a View to show/hide something, as we have no View reference here but just a flow of events/states and there are some cases when it's hard to convert/reduce some event to some new state. Consider a zoom-in-click: you tell your ViewModel that your user's just pressed that button and you need that your map increases zoom level. How to communicate that command to your View?
Would you consider a good practice for a ViewModel to expose the following `ViewState`:
sealed class MapViewState {
sealed class Features : MapViewState() {
data class StandByFeatures(val features : List<GeoJsonFeature>) : Features()
sealed class SearchFeatures : Features() {
data class SearchCategoryFeatures(val features : List<GeoJsonFeature>) : SearchFeatures()
data class SearchResultFeatures(val features : List<GeoJsonFeature>) : SearchFeatures()
}
data class Routes(val features : List<GeoJsonFeature>) : Features()
}
sealed class Command : MapViewState() {
object IncreaseZoom : Command()
object DescreaseZoom : Command()
object ToggleSatellite : Command()
}
}
I feel like breaking some contract here because now my ViewModel seems to be strongly coupled to the view: because it knows what to command. Am I right? What would be a good solution here? Any help would be appreciated.