Skip to content

Mobius.kt

Maven Central Sonatype Nexus (Snapshots) Codecov

Kotlin Multiplatform framework for managing state evolution and side-effects, based on spotify/Mobius.

Features:

  • Support for all Kotlin Multiplatform targets
  • API surface usable from Kotlin, Java, Swift, and Javascript
  • Coroutine and Flow support
  • Testing utilities module
  • Reduced boilerplate with code generation
  • No runtime dependencies (*atomicfu for Native targets)

Getting Started

Download

API Docs

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

Mobius Loop Diagram

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: Spotify/Mobius - Concepts > Mobius Loop)

Why Mobius.kt

By combining Mobius Loops with Kotlin's Multiplatform features, mobius.kt allows you to write and test Update functions in platform-independent (common) Kotlin and deploy them everywhere. This leaves impure functions to be written in multiplatform Kotlin code or the target platform's primary language (Js, Java, Objective-c/Swift), depending on your use-case.