Provide a simple redux-like framework for the JavaFx WebView component
Provides a simple redux-like framework for the JavaFx WebView component.
See CounterExample.kt which demonstrates
basic usage.
Available from the jcenter repository.
Maven:
```Maven POM
Gradle:
```Gradle
compile 'com.github.sgdan:webview-redux:0.0.1'
The Redux.kt class can be instantiated by providing:
The view function can use the kotlinx.html DSL to
build the view from the state:
fun view(state: Int): Node = createDoc().create.html {
body {
h1 { +"Counter" }
+"Current value: $state"
}
}
An Animation timer is used so that the view function won’t be used more than once per screen
refresh cycle.
The Redux class adds a performAction
function to the JavaScript
context of the WebView. This allows code in the view function to create named action events
with optional parameters:
button {
+"Clear"
onClick = "performAction('CLEAR');"
}
button {
+"Enter"
onClick = "performAction('ENTER', document.getElementById('input1').value, 'arg');"
}
Events can also be triggered from a background thread or co-routine:
launch {
while (true) {
delay(1000)
redux.perform(Action.TICK)
}
}