mitchtabian / Open-API-Android-App

Kotlin, MVI, Hilt, Retrofit2, Coroutines, Room Persistence, REST API, Token Authentication

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

some serious issue in viewModel

razaghimahdi opened this issue · comments

so when i try to multi trigger events it doesnt work correctly, for example i was testing BlogViewModel in init method i called some onTriggerEvent on purpose, then i find out list sets empty, why this happened? what we should do to solve that?

so finally after two days i think i got solution:
i tied to use old fashioned way

i deleted:

this.state.value = state.copy(
                        order = order,
                        filter = filter
                    )

and used this:

    fun getCurrentViewStateOrNew(): BlogState{
        val value = state.value?.let{
            it
        }?: BlogState()
        return value
    }

    fun setViewState(viewState: BlogState){
        state.value = viewState
    }

i have no idea why this works and why that one doesn't works,
any idea?