Hey everyone, our team is considering using this l...
# mvikotlin
t
Hey everyone, our team is considering using this library as a way to maximize code sharing. It is our understanding that with this library, we can share everything except the UI. What we really wanted to do is to share our ViewModel logic. From reading the docs, and inspecting the sample (keep in mind, we haven't studied MVI pattern before), one question popped off: • controller = createController(lifecycle.asMviLifecycle()) -- is this similar to doing viewModel by viewmodels()? What I mean by this question is: Is a Controller similar to a ViewModel in terms of lifecycle?
a
As mentioned in the readme and the docs, the only library's responsibility is: • To provide a single source of truth for 
State
 (the scope is not defined, it can be a whole app, a screen, a feature, or a part of a feature); • To provide an abstraction for UI with efficient updates (however this is not obligatory, you can use whatever you want); • To provide lifecycle aware connections (binding) between inputs and outputs (again this is not obligatory in any way).
Everything else is out of scope of the library, there are no definitions for “screens”, “features”, “modules”, etc.
You can find one of the architecture options in the samples. Again, this is just an example of one possible solution.
The idea behind the
Controller
is just to demonstrate how the library can be used in the shared code. It is more close to the Android Fragment.
For
ViewModel
-like behaviour you can consider the `InstanceKeeper`: https://arkivanov.github.io/MVIKotlin/state_preservation.html Or you can also check the Decompose library, it allows you to share the Navigation logic as well, and basically scopes your "screens" with a lifecycle. But this is assuming your are going using Jetpack Compose/SwiftUI or other declarative UI frameworks. For Android Views/UIKit it might be tricky to integrate.
👍 1
t
Thanks @Arkadii Ivanov, we'll have a look at Decompose!
K 1