Skip to content

Instantly share code, notes, and snippets.

@galex
Created July 3, 2025 03:55
Show Gist options
  • Save galex/fc70d1cf094117487b568f03a6299db5 to your computer and use it in GitHub Desktop.
Save galex/fc70d1cf094117487b568f03a6299db5 to your computer and use it in GitHub Desktop.
Back to the original MVIViewModel!
abstract class MVIViewModel<State, Event>(
protected val savedStateHandle: SavedStateHandle? = null,
) : ViewModel() {
private val _uiState by lazy { MutableStateFlow(initialState()) }
val uiState get() = _uiState.asStateFlow()
fun update(block: State.() -> State) {
_uiState.update(block)
}
abstract fun initialState(): State
abstract fun handleEvent(event: Event)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment