Just finished a new POC with Orbit on KMM grounds....
# orbit-mvi
g
Just finished a new POC with Orbit on KMM grounds. Not yet ready to make it public (SwiftUI time), but I can share a quick feedback about KMM/Android: ❤️ - there you go. A quick question: I know there’s no SavedStateHandle logic in KMM, but how one can save state when sharing ViewModels? 🤔 Is it even possible?
a
really the best is to cache data at a different layer, for example in a database backed by sqldelight or for small amounts of data you could use multiplatform-settings
👍 1
i did originally play with multiplatform saved state but to be honest the way state saving works on iOS didn't sit well with me - i was looking at it from a process death point of view but the lifecycle of the data is longer than that of SavedStateHandle
g
do you have any sample I could look into?
what I like about SavedStateHandle is the “auto setup/restore” it offers, I was thinking trying using multiplatform-settings, but that means I have to manually save the state every reduce operation 🤔 makes sense? Then in the container init I check if I have something cached, on
override fun onCleared()
I call .clear() problems: • saving in cache upon any reduce may not be optimal • how do i clear this cache when user kills the app manually, in other words, how can I distinguish between system kill or user kill (the latter I want a cache cleared)? 🤔
m
https://github.com/orbit-mvi/orbit-sample-posts-multiplatform cmiiw, this should be the sample for KMM using orbit-mvi
g
yup but that sample doesn’t have state restore logic, or am I wrong?
@appmattus actually theres a way to solve problem 2
how do i clear this cache when user kills the app manually, in other words, how can I distinguish between system kill or user kill (the latter I want a cache cleared)?
a very very 🔨 time one 😅 , clearing cache if splash launches 😬
Copy code
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
it works but i don’t like it very much…
a
and then comes the problem of the functionality working the same on iOS 🤣🤣🤣
g
ahah yeah, god damn it
a
The way the state saving works at the moment is every change is sent through the savedstatehandle but I believe that manages persistence in a sane way for you
g
yup i actually like the way orbit handles this (without VM shared)
a
No not really and no sample to look at either. I was mainly messing around in pure swift code to understand how things worked there rather than having anything usable - this was before the swift generation plugin existed though so I was struggling to see how I'd get anything into Multiplatform code
👍 1
g
do you think we could have a shared VM with the “core” logic, let’s say, and then on each plat. we extend that VM to implement state restore?
I was imagining the VM also observing the state flow
dunno 🤔
a
In theory yes, my concern is the amount of boilerplate someone would have to write… What we had thought about was a platform independent wrapper around savedstatehandle that you'd have to provide to the container. I'm sure the problem is solvable so really it's a problem of time. I wanted to better publish what we do have working for KMM first before tackling this problem or we won't get anything out of the door.
g
Yup that sounds a good idea
a
It's hacktoberfest so rather selfishly I've been spending time on some of my other open source projects otherwise they get no love
g
yes I totally get you 😉
I’m very happy with the state of orbit, thanks for your work guys
m
do you think we could have a shared VM with the “core” logic, let’s say, and then on each plat.
afaik https://danielebaroncelli.medium.com/ shares a lot related to use a shared VM
g
Thanks for your input @miqbaldc, that articles series are very good
in its example: https://github.com/dbaroncelli/D-KMP-sample/blob/main/shared/src/commonMain/kotlin/eu/baroncelli/dkmpsample/shared/viewmodel/StateManager.kt I could be wrong, but I get the feeling this class tries to implement an MVI logic
I did not found state restore, maybe I’ve missed it.
a
yes, in Daniele's articles he talks about MVI being the natural architecture for KMM although he's gone a lot further in modelling the navigation as part of the app state whereas in Orbit we leave that to the platform - as far as i can tell there is no attempt to store the state for restoration
👍 2