<@U019WDTQTS6> I'm curious, why are you using mole...
# squarelibraries
k
@xxfast I'm curious, why are you using molecule in compose desktop versus just using compose through the whole callstack?
x
i like using swiftui for the apple platforms ._.
k
We use molecule solely on iOS platforms and tests and use the current composition for our compose business layer directly on android. No need for a middle molecule flow layer. I think you could do the same on desktop
(We also use swift ui on iOS)
j
Desktop doesn't necessarily mean Desktop Compose UI
k
That would explain my misunderstanding!
x
in my setup i have a shared view model (where i use molecule), and this is shared with a compose-android, compose-desktop, ios-swift-ui, compose-web and a vanila react-frontend
k
Take what I say with a grain of salt, because I am not familiar with your architecture, but you might consider exposing a composable function from your viewmodel/presentation layer. Below is verbatim what our viewmodel interface is.
Copy code
interface ComposeViewModel<Action : Any, ViewState : Any> {

  @Composable fun viewState(events: Flow<Action>): ViewState
}
You can then bind that composable to the underlying platform using molecule or just use the current composition directly.
anyway enough armchair engineering for me, I'm sure your situation is more nuanced than that 🙂
x
yeah I could 🤔 but im using a bunch of other tooling help me manage view models for ios which kinda relies on it being exposed as a
StateFlow
k
yup I recently had to deal with something similar. I have a bi-facial iOS platform binding which treats the stateflow molecule produces as an internal impl detail in kotlin so I don't have to finnick with Swift/Kotlin flow interop. We expose callbacks and an
initialState
from the kotlin side and then the swift side ties that into SwiftUi views
It allowed us to get rid of kmp-coroutines by the same author. I'm not sure if it's similar to the above library though
x
i see - still wiring up my architecture with molecule, so i might even end up just exposing a composable function (with a initialState) if that helps me simplify 😅
k
It helped us greatly simplify
Good luck!
e
Accidentally deleted my comment when I went to edit it I think it would be worth adding a paragraph about using molecule from a purely Compose UI app to the README. Whether it is necessary, alternatives, tradeoffs, etc...
k
Feel free to open an issue on Molecule's repo, but it's my personal opinion that the library shouldn't be in the business of dictating what your overall architecture looks like 😅 .
e
Will do. I think it's less dictating what the architecture should be and more informing if it's technically necessary to use molecule in that situation and if/what you lose by not using it.