Created
September 23, 2020 13:02
-
-
Save jshvarts/9b075c83c19d6ea188dae4e762457254 to your computer and use it in GitHub Desktop.
errorEffectOrEvent
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
// In ViewModel: | |
private val error = ConflatedBroadcastChannel<ErrorType>() | |
fun errorEffect(): Flow<ErrorType> = error.asFlow() | |
val errorType = if (connectionHelper.isConnected()) { | |
ErrorType.GENERIC | |
} else { | |
ErrorType.CONNECTION | |
} | |
error.offer(errorType) | |
// In Fragment: | |
viewLifecycleOwner.lifecycleScope.launch { | |
viewModel.errorEffect().collect { | |
renderErrorState(it) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment