kt-mvvm / com.dukescript.api.kt / Model / Provider

Provider

interface Provider

Interface to implement by objects that willing to expose its properties (e.g. com.dukescript.api.kt.observable, com.dukescript.api.kt.observableList or com.dukescript.api.kt.computed) as Models. Trivial implementation can look like this:

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

    public var value: Int by observable(0)
}

Properties

objs

abstract val objs: Model

The property to fill with Model instance associated your object.

Extension Functions

action

fun Provider.action(f: () -> Unit): Readable<Action>

Creates a handler to react on action happening in the user interface.

actionWithData

fun <T> Provider.actionWithData(f: (T?) -> Unit): Readable<Action>
fun <T> Provider.actionWithData(type: Class<T>, f: (T?) -> Unit): Readable<Action>

Creates a handler to react on action happening in the user interface and provide identification of the interface element that triggered the action.

computed

fun <T> Provider.computed(fn: () -> T): Readable<T>

Defines derived, computed property. Its value depends on other properties and is recomputed when those dependant properties change.

loadJSON

fun <T> Provider.loadJSON(baseUrl: String, onSuccess: (List<T>) -> Unit, onError: (Throwable) -> Unit = null, method: String = "GET", data: Any? = null, headers: Map<String, String>? = null, afterUrl: String? = null): Unit

Initializes an asynchronous REST connection and calls back when a result is obtained.

observable

fun <T> Provider.observable(initialValue: T, onChange: () -> Unit = null): Writable<T>

Defines an observable property.

observableList

fun <T> Provider.observableList(vararg items: T, onChange: () -> Unit = null): Readable<MutableList<T>>

Defines an observable array property.