Ashu Tyagi
01/12/2024, 9:03 PMSKIE
.
So I have an abstract class which looks something like this
abstract class BaseViewModel<Event : UiEvent, State : UiState, Effect : UiEffect> : ViewModel() {
abstract suspend fun handleEvent(event: Event)
suspend fun setEvent(event: Event) {
val newEvent = event
_event.emit(newEvent)
}
protected suspend fun setState(reduce: State.() -> State) {
val newState = currentState.reduce()
_uiState.emit(newState)
}
protected suspend fun setEffect(builder: () -> Effect) {
val effectValue = builder()
_effect.emit(effectValue)
}
}
Then I have a ViewModel which extends this BaseViewModel, something like this:
class HomePageViewModel(
private val fetchFeaturedPlaylistsUseCase: FetchFeaturedPlaylistsUseCase,
private val fetchFeaturedAlbumsUseCase: FetchFeaturedAlbumsUseCase
) : BaseViewModel<HomePageContract.Event, HomePageContract.State, HomePageContract.Effect>() {
suspend fun init() {
subscribeEvents()
}
private suspend fun fetchHomePageData() {
}
override suspend fun handleEvent(event: HomePageContract.Event) {
when (event) {
HomePageContract.Event.OnFetchHomePageEvent -> {
fetchHomePageData()
}
}
}
override fun onCleared() {
super.onCleared()
}
}
Now I have to call setEffect
which is a suspend
function. SKIE converts them to Swift async functions. But I'm not able to access setEffect (which comes from base class) on HomePageViewModel but I'm able to call init()
which is also a suspend
function but is defined in HomePageViewModel instead of BaseViewModel.
Also, I can see an async function for init() but not for setEffect or other suspend function from abstract class (screenshots attached below).
Sorry for the long post. Thanks in advance.Ashu Tyagi
01/12/2024, 9:03 PMFilip Dolník
01/15/2024, 8:27 AMAshu Tyagi
01/15/2024, 6:34 PM