项目作者: sgdan

项目描述 :
Provide a simple redux-like framework for the JavaFx WebView component
高级语言: Kotlin
项目地址: git://github.com/sgdan/webview-redux.git
创建时间: 2018-01-04T06:42:09Z
项目社区:https://github.com/sgdan/webview-redux

开源协议:MIT License

下载


webview-redux Build Status Download

Provides a simple redux-like framework for the JavaFx WebView component.

See CounterExample.kt which demonstrates
basic usage.

Get started

Available from the jcenter repository.

Maven:
```Maven POM


com.github.sgdan
webview-redux
0.0.1

  1. Gradle:
  2. ```Gradle
  3. compile 'com.github.sgdan:webview-redux:0.0.1'

Redux class

The 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 to
build the view from the state:

  1. fun view(state: Int): Node = createDoc().create.html {
  2. body {
  3. h1 { +"Counter" }
  4. +"Current value: $state"
  5. }
  6. }

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:

  1. button {
  2. +"Clear"
  3. onClick = "performAction('CLEAR');"
  4. }
  5. button {
  6. +"Enter"
  7. onClick = "performAction('ENTER', document.getElementById('input1').value, 'arg');"
  8. }

Events can also be triggered from a background thread or co-routine:

  1. launch {
  2. while (true) {
  3. delay(1000)
  4. redux.perform(Action.TICK)
  5. }
  6. }