Last active
July 7, 2023 14:10
-
-
Save kaszabimre/c790f2c343e38b512f934efb9d3f6b54 to your computer and use it in GitHub Desktop.
Reducer implementation v1
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
interface UiState | |
interface UiEvent | |
abstract class Reducer<S : UiState, E : UiEvent>(initialVal: S) : ViewModel() { | |
//... | |
private val _state: MutableStateFlow<S> = MutableStateFlow(initialVal) | |
val state: StateFlow<S> | |
get() = _state | |
private val _error: MutableStateFlow<String?> = MutableStateFlow(null) | |
val error: StateFlow<String?> | |
get() = _error | |
val stateFlowAdapter = state.asCallbacks() | |
val errorFlowAdapter = error.asCallbacks() | |
private fun <T : Any?> StateFlow<T>.asCallbacks() = FlowAdapter(viewModelScope, this) | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment