kt-mvvm

Cross-Platform Model View ViewModel with Kotlin

View on GitHub

Model View ViewModel for Kotlin

We love Kotlin. We love MVVM. This is the result.

The ViewModel:

class Demo : Model.Provider {
    override val objs = Model(this)

    var desc by observable("")
    val todos: MutableList<String> by observableList()

    val addTodo by action {
        todos += desc
        desc = ""
    }
}

The View:

<label for="key">New Todo:</label>
<input id="key" type="text" data-bind="textInput: desc"/>
<button data-bind="click: addTodo">Add</button>
<ul class="todos" data-bind='foreach: todos'>
    <li>
        <span data-bind="text: $data"></span>
    </li>
</ul>

Getting Started

Clone the demo repository to give Kotlin and MVVM a try:

$ git clone https://github.com/dukescript/kt-mvvm-demo.git
$ cd kt-mvvm-demo
$ ./gradlew run # or: mvn package exec:exec

then edit the application logic or the application UI as

$ open src/main/java/com/kt/mvvm/demo/Demo.kt
$ open src/main/webapp/pages/index.html

and build and execute your application again to see outcome of your changes:

$ ./gradlew run
# or if you want to use Maven invoke:
$ mvn package exec:exec

Repeat until your application becomes as slick as needed!

Documentation

Use observable, observableList and computed functions to define intrinsic well connected properties that together form model(s) for your user interface, network communication, etc. Use action/actionWithData to define handlers of interactions arriving from the user interface, network or elsewhere.

Get the overall picture at the KDoc for the whole Kotlin MVVM API.

Our bindings for the HTML-based view are documented here.

Cross platform

With kt-mvvm you write your application once and deploy it to desktop, Android , iOS and browser with the help of portable presenters.

Connected Applications

kt-mvvm offers really smooth integration with REST backends - see loadJSON for more details.

License

The kt-mvvm API is licensed under Apache 2.0 license. The default JavaFX WebView based presenter comes directly from an Apache project. As such one can have fully functional system covered by benevolent Apache license.

Alternative presenters or rendering environments come with their own licensing terms.

Commercial support for the overall ecosystem is available via the DukeScript project channels.