-
-
Save uteke/5a062bd23efde6562d7d996db9fa6e32 to your computer and use it in GitHub Desktop.
UserListViewModel MVI example
This file contains 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
class UserListViewModel(...): ViewModel() { | |
private val _viewStateFlow = MutableStateFlow<ViewState>() | |
private val _eventChannel: Channel<Event> = Channel(BUFFERED) | |
val viewStateFlow: Flow<ViewState> = _viewStateFlow | |
val eventFlow: Flow<Event> = _eventChannel.receiveAsFlow() | |
fun process(action: Action) { | |
is Action.CheckConnectivity -> checkConnectivity() | |
is Action.Load -> load(...) | |
is Action.Reload -> load(...) | |
is Action.EmailClick -> emailClick(uuid = action.uuid) | |
is Action.PhoneClick -> phoneClick(uuid = action.uuid) | |
} | |
private fun checkConnectivity() { ... } | |
private fun load(...) { ... } | |
private fun emailClick(uuid: String) { ... } | |
private fun phoneClick(uuid: String) { ... } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment