Skip to content

Instantly share code, notes, and snippets.

@uteke
Last active September 1, 2023 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uteke/5a062bd23efde6562d7d996db9fa6e32 to your computer and use it in GitHub Desktop.
Save uteke/5a062bd23efde6562d7d996db9fa6e32 to your computer and use it in GitHub Desktop.
UserListViewModel MVI example
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