icerockdev / moko-mvvm

Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
994 stars 95 forks source link

ViewModel calls init block, functions two times when they are called from screen #225

Closed Mukhammaddin6567 closed 1 year ago

Mukhammaddin6567 commented 1 year ago

Hi, Moko team. I got the issue. It is when i call view model , its init block called twice. then when i use one of the functions inside viewmodel it works twice too

Alex009 commented 1 year ago

hi. i think you have two instances of same viewmodel class. just add println("vm: $this") to see that it's not same object

Mukhammaddin6567 commented 1 year ago

@Alex009 objects are the same. I already did it

Alex009 commented 1 year ago

init block can't be called twice in one object. it's kotlin behaviour, not library. can you prepare sample repository with this bug?

Mukhammaddin6567 commented 1 year ago

@Alex009 okay I will do it as soon as possible

Mukhammaddin6567 commented 1 year ago

we're providing viewmodel through koin... can this be due to koin? Do you have sample usage with koin?

Mukhammaddin6567 commented 1 year ago

@Alex009 Hi. Can you check your gmail?

Alex009 commented 1 year ago

@Mukhammaddin6567 i check my email but not see any mails. are you send something? did you found reason of bug?

Mukhammaddin6567 commented 1 year ago

@Alex009 Hi. I found what is the problem. it's not related to moko-mvvm.

Mukhammaddin6567 commented 1 year ago

@Alex009 yes I found reason of bug. It was ktor problem