Skip to content

Instantly share code, notes, and snippets.

@krzdabrowski
Last active April 2, 2024 19:14
Show Gist options
  • Save krzdabrowski/9f98de2a999920cf8a6478735ac398dc to your computer and use it in GitHub Desktop.
Save krzdabrowski/9f98de2a999920cf8a6478735ac398dc to your computer and use it in GitHub Desktop.
abstract class BaseViewModel<UI_STATE : Parcelable, PARTIAL_UI_STATE, EVENT, INTENT>(
(...)
) : ViewModel(),
IntentDelegate<INTENT, PARTIAL_UI_STATE> by IntentDelegateImpl(),
InternalChangesDelegate<PARTIAL_UI_STATE> by InternalChangesDelegateImpl(),
EventDelegate<EVENT> by EventDelegateImpl() {
init {
viewModelScope.launch {
merge(
getIntents(::mapIntents),
getInternalChanges(),
)
.scan(uiState.value, ::reduceUiState)
.catch { Timber.e(it) }
.collect {
savedStateHandle[SAVED_UI_STATE_KEY] = it
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment