https://github.com/yukukotani/kotlin-hyperapp
Hyperapp wrapper for Kotlin/JS.
https://github.com/yukukotani/kotlin-hyperapp
hyperapp kotlin kotlinjs
Last synced: 6 days ago
JSON representation
Hyperapp wrapper for Kotlin/JS.
- Host: GitHub
- URL: https://github.com/yukukotani/kotlin-hyperapp
- Owner: yukukotani
- License: apache-2.0
- Created: 2019-07-12T10:39:55.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-19T10:06:51.000Z (almost 7 years ago)
- Last Synced: 2025-03-03T07:43:53.776Z (over 1 year ago)
- Topics: hyperapp, kotlin, kotlinjs
- Language: Kotlin
- Homepage:
- Size: 72.3 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kotlin-hyperapp
[  ](https://bintray.com/monchi/maven/kotlin-hyperapp/_latestVersion)
[Hyperapp](https://github.com/jorgebucaran/hyperapp) wrapper for Kotlin/JS.
## Installation
```groovy
repositories {
jcenter()
}
dependencies {
implementation "land.mog:kotlin-hyperapp:${version}"
}
```
## Usage
First, you can define type of state and actions.
```kotlin
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.
```kotlin
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.
```kotlin
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](https://github.com/Monchi/kotlin-hyperapp/tree/master/example).
## Build
To build, you need simply run this command:
```bash
./gradlew :kotlin-hyperapp:build
```
## License
This project is licensed under the [Apache license 2.0](https://github.com/Monchi/kotlin-hyperapp/blob/master/LICENSE).