Hello! I’ve a question for the authors regarding t...
# orbit-mvi
g
Hello! I’ve a question for the authors regarding this:
fun <STATE : Parcelable, SIDE_EFFECT : Any> ViewModel.container(...)
Why forcing 
kotlinx.parcelize.Parcelize
 when we could also use 
kotlinx.serialization.Serializable
 ? 🤔 According to the docs if we want to store something in disk, Serializable would be preferable, where Parcelize would be the choice for IPC situations. SaveStateHandle also supports Serializable What do you think about adding an extension that receives as 
STATE: Serializable
?
m
@Guilherme Delgado No special reason - just at the time we wanted to get process death handled on Android relatively quickly 🙂 It’s actually on our roadmap to review how we handle state saving - particularly from a multiplatform POV. We will take your suggestion into account!
g
Yes KMM will be a different issue. I’m very interested in seeing how you’ll solve it 😊 In the meantime would you accept a PR with this change for Android projects?
(I am using Orbit MVI in a KMM project but not yet in the shared module. I would like to avoid using moko parcelize in some shared models that endup in the viewmodel. That’s where Serializable comes in hand 😅 )
a
No reason why a Parcelable couldn't be written to disk imo! We use Parcelable because its the easier choice on Android; not that it would be hard to store a kotlinx Serializable in the saved state handle (just Parcelable was quicker to implement). Be cautious of all these Serializable classes though, SavedStateHandle supports java Serializable not kotlinx. The Java implementation is slow not least because it uses reflection throughout. Parcelable on the other hand has parsers explicitly written for performance. If we're able to get saved state working for multiplatform then we would look to use kotlinx Serializable.
👍 1
💯 1
✍️ 1
☝️ 2
There are projects such as this to bridge the gap between kotlinx and parcelable that could prove useful... although yet to use it myself https://github.com/chRyNaN/serialization-parcelable Also worth noting, Parcelable doesn't add any other dependencies into a project whereas kotlinx Serializable does - granted KMM wise you're probably already using it. The project still needs to serialize to something SavedStateHandle supports so there will be the dependency on the json module (or another format) from kotlinx too
g
other motivation I can think of - for using kotlinx.serialization - is if I’m using a shared model that uses moko.Parcelable, later if I want to save it in the viewModel it will complain:
Type is not directly supported by ‘Parcelize’. Annotate the parameter type with ‘@RawValue’ if you want it to be serialized using ‘writeValue()’