hhariri / oolong

MVU for Kotlin Multiplatform

Home Page:https://oolong-kt.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Oolong

Build Status Maven Central Sonatype Nexus (Snapshots) License Gitter chat

Oolong is an Elm inspired Model-View-Update (MVU) implementation for Kotiln multiplatform. As the name implies, three core concepts comprise the foundation of this architecture:

  • Model - a type to represent the program state

  • View - a function to map the state to view properties

  • Update - a function to update the state

By applying this simple pattern you can create composable, testable programs that can run on any platform. Oolong enables a common codebase for all platforms by using a Render function which is implemented by each frontend.

Get started with Oolong by reading the official guide.

Example

The following is a simple counter example in which the count can be incremented or decremented.

object Counter {

    data class Model(
        val count: Int = 0
    )

    sealed class Msg {
        object Increment : Msg()
        object Decrement : Msg()
    }

    class Props(
        val count: Int,
        val increment: () -> Msg,
        val decrement: () -> Msg
    )

    val init: Init<Model, Msg> = { 
        Model() to none()
    }

    val update: Update<Model, Msg> = { msg, model ->
        when (msg) {
            Msg.Increment -> model.copy(count = model.count + 1)
            Msg.Decrement -> model.copy(count = model.count - 1)
        } to none()
    }

    val view: View<Model, Props> = { model ->
        Props(
            model.count,
            { Msg.Increment },
            { Msg.Decrement }
        )
    }

}

Samples

More examples can be found in the samples repository.

Documentation

Further reading can be found in the official guide and documentation.

Download

dependencies {
    implementation("org.oolong-kt:oolong:2.0.2")
}

About

MVU for Kotlin Multiplatform

https://oolong-kt.org

License:Apache License 2.0


Languages

Language:Kotlin 97.0%Language:Shell 3.0%