|
1 |
| -# KWeb |
| 1 | +### KWeb, an experimental Kotlin framework for building rich interactive web applications in pure Kotlin |
2 | 2 |
|
3 |
| -## Overview |
| 3 | +The idea behind KWeb is to treat the web browser as a fairly dumb robot, keeping most of the intelligence server-side, |
| 4 | +relaying instructions to the client via a websocket, and receiving responses from the client. KWeb takes advantage |
| 5 | +of the new coroutines functionality in the upcoming Kotlin 1.1 to handle asynchronously waiting for responses |
| 6 | +from the client in a way that's almost transparent to the user of KWeb. |
4 | 7 |
|
| 8 | +#### Status - 2017-01-08 |
| 9 | +KWeb is currently very experimental, at this stage more of a proof-of-concept and playground for ideas than anything |
| 10 | +even close to being useful in production. |
5 | 11 |
|
| 12 | +#### Getting started |
| 13 | +1. Ensure you are using the "Early Access Preview 1.1" Kotlin plugin in IDEA, see "How to Try It" section at the |
| 14 | +bottom of JetBrain's [announcement](https://blog.jetbrains.com/kotlin/2016/12/kotlin-1-1-m04-is-here/). |
| 15 | +2. Clone the repository and open as a Gradle project in IntelliJ IDEA: `git@github.com:sanity/kweb.git` |
6 | 16 |
|
7 |
| -## Features |
| 17 | +#### An introductory demo |
8 | 18 |
|
9 |
| -## Usage |
| 19 | +A very simple implementation of the old-perennial: the to-do list. Allows you to add items to a list, and remove |
| 20 | +them by clicking on them. |
10 | 21 |
|
11 |
| -### Adding library dependency |
| 22 | +This makes use of the very useful apply() function, if you're unfamiliar with it I recommend you read |
| 23 | +[Exploring the Kotlin Standard Library](http://beust.com/weblog/2015/10/30/exploring-the-kotlin-standard-library/). |
12 | 24 |
|
13 |
| -You can use this library by adding a dependency for Gradle, Maven, SBT, Leiningen or another Maven-compatible dependency management system thanks to Jitpack: |
| 25 | +Take a look at [the code](https://github.com/sanity/kweb/blob/master/src/main/kotlin/com/github/sanity/kweb/demos/todo/todo.kt). |
14 | 26 |
|
15 |
| -[](https://jitpack.io/#sanity/kweb) |
16 |
| - |
17 |
| -### Basic usage from Kotlin |
18 |
| - |
19 |
| -```kotlin |
20 |
| -import com.github.sanity.kweb.clientConduits.WebsocketsClientConduit |
21 |
| -import kotlinx.coroutines.async |
22 |
| -import kotlin.concurrent.thread |
23 |
| - |
24 |
| -fun main(args: Array<String>) { |
25 |
| - WebsocketsClientConduit(8091) { |
26 |
| - thread { |
27 |
| - async { |
28 |
| - var clicks = 0 |
29 |
| - val heading = doc.body.new("h1") |
30 |
| - heading.setInnerHTML("0 clicks") |
31 |
| - heading.addEventListener("click") { |
32 |
| - clicks++ |
33 |
| - heading.setInnerHTML("$clicks clicks") |
34 |
| - false |
35 |
| - } |
36 |
| - } |
37 |
| - } |
38 |
| - false |
39 |
| - } |
40 |
| - Thread.sleep(10000) |
41 |
| -} |
42 |
| - |
43 |
| -``` |
44 |
| - |
45 |
| -### License |
46 |
| -Released under the [LGPL](https://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License) version 3 by [Ian Clarke](http://blog.locut.us/) of [Stacks](http://trystacks.com/). |
| 27 | +##### Try it |
| 28 | +1. Take a look at `src/main/kotlin/com/github/sanity/kweb/demos/todo/todo.kt` in IDEA |
| 29 | +2. Run it |
| 30 | +3. Visit [http://127.0.0.1:8091/](http://127.0.0.1:8091/) in your browser. |
0 commit comments