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.
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 }
)
}
}
More examples can be found in the samples repository.
Further reading can be found in the official guide and documentation.
dependencies {
implementation("org.oolong-kt:oolong:2.0.2")
}