Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sgdan/webview-redux
Provide a simple redux-like framework for the JavaFx WebView component
https://github.com/sgdan/webview-redux
gui javafx kotlin redux webview
Last synced: about 2 months ago
JSON representation
Provide a simple redux-like framework for the JavaFx WebView component
- Host: GitHub
- URL: https://github.com/sgdan/webview-redux
- Owner: sgdan
- License: mit
- Created: 2018-01-04T06:42:09.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-11T00:02:49.000Z (almost 7 years ago)
- Last Synced: 2024-08-04T01:28:28.375Z (5 months ago)
- Topics: gui, javafx, kotlin, redux, webview
- Language: Kotlin
- Size: 80.1 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - webview-redux - like framework for the JavaFx WebView component | sgdan | 3 | (Kotlin)
README
# webview-redux [![Build Status](https://travis-ci.org/sgdan/webview-redux.svg?branch=master)](https://travis-ci.org/sgdan/webview-redux) [![Download](https://api.bintray.com/packages/sgdan/maven-releases/webview-redux/images/download.svg)](https://bintray.com/sgdan/maven-releases/webview-redux/_latestVersion)
Provides a simple redux-like framework for the JavaFx WebView component.See [CounterExample.kt](src/test/kotlin/com/github/sgdan/webviewredux/CounterExample.kt) which demonstrates
basic usage.### Get started
Available from the jcenter repository.Maven:
```Maven POMcom.github.sgdan
webview-redux
0.0.1```
Gradle:
```Gradle
compile 'com.github.sgdan:webview-redux:0.0.1'
```### Redux class
The [Redux.kt](src/main/kotlin/com/github/sgdan/webviewredux/Redux.kt) class can be instantiated by providing:
- a WebView component to use as display
- the initial state: State
- a view function: (State) -> View
- an update function: (State, Action) -> State### View function
The view function can use the [kotlinx.html DSL](https://github.com/Kotlin/kotlinx.html) to
build the view from the state:
```Kotlin
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.### Events
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:
```Kotlin
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:
```Kotlin
launch {
while (true) {
delay(1000)
redux.perform(Action.TICK)
}
}
```