Created
July 3, 2025 03:55
-
-
Save galex/fc70d1cf094117487b568f03a6299db5 to your computer and use it in GitHub Desktop.
Back to the original MVIViewModel!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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