mobius.kt
Multiplatform Kotlin Mobius implementation.
What is Mobius?
The core construct provided by Mobius is the Mobius Loop, best described by the official documentation. (Embedded below)
A Mobius loop is a part of an application, usually including a user interface.
In a Spotify context, there is usually one loop per feature such as “the album page”, “login flow”, etc., but a loop can also be UI-less and for instance be tied to the lifecycle of an application or a user session.
Mobius Loop
A Mobius loop receives Events, which are passed to an Update function together with the current Model.
As a result of running the Update function, the Model might change, and Effects might get dispatched.
The Model can be observed by the user interface, and the Effects are received and executed by an Effect Handler.
'Pure' in the diagram refers to pure functions, functions whose output only depends on their inputs, and whose execution has no observable side effects.
See Pure vs Impure Functions for more details.
(Source: Concepts > Mobius Loop)
By combining this concept with Kotlin's MPP features, mobius.kt allows you to write and test all of your pure functions (application and/or business logic) in Kotlin and deploy it everywhere.
This leaves impure functions to the native platform, which can be written in their primary language (Js, Java, Objective-c/Swift) or in Kotlin!
Samples
Todo
iOS
Open and run the samples/todo/todo-ios
Xcode project, it contains a build step to produce the Kotlin framework.
Note the first build will take some time while it downloads all the necessary dependencies.
Download
repositories {
mavenCentral()
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
dependencies {
implementation("org.drewcarlson:mobius-core:$MOBIUS_VERSION")
implementation("org.drewcarlson:mobius-extras:$MOBIUS_VERSION")
implementation("org.drewcarlson:mobius-android:$MOBIUS_VERSION")
}