rickclephas / KMP-ObservableViewModel

Library to use AndroidX/Kotlin ViewModels with SwiftUI
MIT License
591 stars 28 forks source link

JVM support #8

Closed joreilly closed 1 year ago

joreilly commented 1 year ago

@rickclephas we chatted a little about this and think you mentioned you might add JVM target at some point and just creating this to track. I can run projects I have that do include JVM target but just get error when syncing.

rickclephas commented 1 year ago

Thanks! Yeah just need to decide what the JVM implementation would be. We can also add more targets in a similar way, e.g. to support Multiplatform compose.

joreilly commented 1 year ago

Perhaps it is reasonable to limit this to KMM (iOS and Android).....some of the so called KMM samples I have also include a Compose for Desktop (JVM) client as well or at least some main() code in jvmMain to do some sanity testing. Not sure what best approach typically is in project like that where library is perhaps only being used for subset of targets.

santoshshetty commented 1 year ago

With Compose Multi platform it would be great if we can target JVM for Native coroutines and KMM viewmodel so that we can share our entire business logic in Desktop as well. This will be a great asset for this great library which you created. Waiting for the support.

rickclephas commented 1 year ago

Hi @santoshshetty! KMP-NativeCoroutines already supports the JVM target, so we are just missing support for it in KMM-ViewModel. The reason it isn't supported yet is because I am unsure what the ViewModel implementation would be for JVM. iOS has a "ViewModel" concept that isn't all that different from an Android ViewModel. I am unaware of a similar concept in the JVM world.

It would be great to have some resources about ViewModels in JVM. So basically we need to answer the following question: how would we use a "ViewModel" in plain JVM (if we forgot about KMP)?

For Compose Multiplatform we could ask a similar question: how would we use a "ViewModel" if we were just using Compose MP on the JVM (without the need to share it with other targets)?

chrisbanes commented 1 year ago

+1 to this. I'm less worried about the JVM target behaving like Android/iOS and more that I can run tests on the JVM.

rickclephas commented 1 year ago

@chrisbanes that should be fairly easy, will take a look at that.

rickclephas commented 1 year ago

v1.0.0-ALPHA-12 adds support for the jvm, js, linuxArm64, linuxX64 and mingwX64 targets. While there isn't any special support for these targets, it does allow projects with these targets to use KMM-ViewModel in commonMain. Making it possible to run tests on the JVM and opens up possibilities for Multiplatform Compose.

I am going to close this issue, but feel free to open a new one if there is a need/possibility to further support one of these targets.