Open-API-Android-App icon indicating copy to clipboard operation
Open-API-Android-App copied to clipboard

some serious issue in viewModel

Open razaghimahdi opened this issue 4 years ago • 1 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?

razaghimahdi avatar Aug 11 '21 15:08 razaghimahdi

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?

razaghimahdi avatar Aug 14 '21 13:08 razaghimahdi