We have most of our code in commonMain, from the ViewModels all the way down (at the lowest layers, we use GraphQL, etc, and a bunch of `actual`s to satisfy the `expect`s).
The code that is Android (Kotlin) or iOS (Swift/Obj-C) is only the UI.
The ViewModels expose observable properties for ui-data to be shown on the screen and for navigation-events.
The ViewModel-properties are
Observable<T>
instances and
class Observable<T>
is of our own making.
The
Observable
take a
viewModelScope
when created and receive the
CoroutineScope
from the UI (lifecycleObserver of Activity or Fragment) when observed. For iOS, for now, the
CoroutineScope
from the UI is just
null
and it will use the
viewModelScope
instead (ie ViewModel’s scope/lifecycle is the same as the scope of the iOS UI)
The UI, in both Android and iOS, creates an instance of this
Observable
with a plain callback
(T) -> Unit
(iOS) or
suspend (T) -> Unit
(Android). The inner-workings of the
Observable
will call this callback when appropriate.