I'm using Redux and somewhere in application I need to check if returning data is not null, then run a function. as you know in redux we should initialize the states like this:
data class ApplicationState(
val movieByGenre : List<DomainMovieModel> = emptyList()
)
the problem is when I check the data ,at the very beginning level, data has been set to empty list, and it satisfies the IF statement
by the way here is the implementation inside view model
fun getMovieByGenre(genreId: Int){
viewModelScope.launch {
val response=repository.getMovieByGenre(genreId)
store.update { currentState->
return@update currentState.copy(movieByGenre = response)
}
}
}
and here is the implementation in fragment:
viewModel.store.stateFlow.map { it.movieByGenre }.distinctUntilChanged().asLiveData().observe(viewLifecycleOwner){
if (it.isEmpty() ){
....
}else{
.....
}
}