I following MVI pattern howevery I feel it is a sh...
# coroutines
p
I following MVI pattern howevery I feel it is a show to put event in a stream then collect it , I want to make handleEvent running asyc without adding with withContext in CardNumberChanged,NameOnCardChanged
Copy code
private fun collectEvents() {
        viewModelScope.launch {
            withContext(Dispatchers.Default) {
                events
                    .collect {
                        handleEvent(it)
                    }
            }
        }
    }
Here is a
Copy code
override fun handleEvent(event: CheckoutViewModelContract.Event) {
    when (event) {
        CheckoutViewModelContract.Event.Initial -> onInitial()
        is CheckoutViewModelContract.Event.CardNumberChanged -> onCardNumberChanged(event.text)
        is CheckoutViewModelContract.Event.NameOnCardChanged -> onNameOnCardChanged(event.text)
        is CheckoutViewModelContract.Event.ExpirationDateChanged -> onCardExpirationDateChanged(
            event.text
        )
c
You can provide the dispatcher directly to the
.launch
call
Copy code
viewModelScope.launch(Dispatchers.Default) { }
🙌 1