I'm attempting to use <molecule> for a CMP app. Fo...
# multiplatform
r
I'm attempting to use molecule for a CMP app. For the view model, I'm basing it off MoleculeViewModel in the
sample-viewmodel
package. Given that
androidx.compose.ui.platform.AndroidUiDispatcher.Main
only exists in
androidMain
, what should I use instead?
Copy code
abstract class MoleculeViewModel<Event, Model> : ViewModel() {
    private val scope = CoroutineScope(
        viewModelScope.coroutineContext + AndroidUiDispatcher.Main <<<<<< Reference not available in commonMain or iosMain
    )

    // ...
}
P.S. I'm new to molecule and the
sample-viewmodel
package has been a helpful starting point. However, I'm open to other approaches.
In order to use a different dispatcher, I've created an
expect
MoleculeViewModel
and then
actual
MoleculeViewModel
for
iosMain
and
androidMain
. However, it would great if there was a dispatcher I could use for both so I can reduce the duplication and just have a single
MoleculeViewModel
in
commonMain
.
c
thank you color 1