compose-multiplatform-viewmodel-base
Installation
SKILL.md
A shared ViewModel base for Compose Multiplatform
The multiplatform ViewModel gives you viewModelScope and onCleared on every target. A project
base class on top of it is worth having for three things and no more: a container handle so a
subclass can pull an occasional dependency without adding a constructor parameter, one loading/error
surface so screens do not each invent theirs, and a logging tag derived from the concrete class.
// adapted — trimmed to the three members worth having, names generalized
abstract class BaseViewModel : ViewModel(), ContainerComponent {
protected val handler: PlaybackHandler by inject()
protected val tag: String = this::class.simpleName ?: "BaseViewModel"
private val _showLoadingDialog = MutableStateFlow(false to "")
val showLoadingDialog: StateFlow<Pair<Boolean, String>> get() = _showLoadingDialog