Hyperapp wrapper for Kotlin/JS.
repositories {
jcenter()
}
dependencies {
implementation "land.mog:kotlin-hyperapp:${version}"
}
First, you can define type of state and actions.
class ExampleState(
val count: Int
) : State
class ExampleActions(
val down: (Int) -> (ExampleState) -> ExampleState,
val up: (Int) -> (ExampleState) -> ExampleState
) : Actions
Then, initialize default value and action.
val initialState = ExampleState(
count = 0
)
val initialActions = ExampleActions(
up = { value -> { state ->
ExampleState(state.count + value)
} },
down = { value -> { state ->
ExampleState(state.count - value)
} }
)
Finally, construct view and run app.
val view = { state: ExampleState, actions: ExampleActions ->
val upAttributes = json(
"onclick" to { actions.up(1) }
)
val downAttributes = json(
"onclick" to { actions.down(1) }
)
h("div", null, arrayOf(
h("h1", null, arrayOf(state.count)),
h("button", downAttributes, arrayOf("-")),
h("button", upAttributes, arrayOf("+"))
))
}
app(initialState, initialActions, view, document.body!!)
You can also see whole example project here.
To build, you need simply run this command:
./gradlew :kotlin-hyperapp:build
This project is licensed under the Apache license 2.0.