Skip to content
This repository has been archived by the owner on Oct 9, 2022. It is now read-only.

Commit

Permalink
Update dom.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Apr 26, 2020
1 parent 825fb4a commit 6115191
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions dom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,27 @@ Kweb can also read from the DOM, in this case the value of an <input> element:

.. code-block:: kotlin
import kweb.Kweb
import kweb.dom.element.creation.tags.*
import kweb.dom.element.events.on
import kweb.dom.element.new
import kweb.state.KVar
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.future.await
import kotlinx.coroutines.launch
fun main() {
Kweb(port = 2395) {
doc.body.new {
val input: InputElement = input()
input.on.submit {
GlobalScope.launch {
val value = input.getValue().await()
println("Value: $value")
}
}
}
}
}
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.future.await
import kotlinx.coroutines.launch
import kweb.InputElement
import kweb.Kweb
import kweb.input
import kweb.new
fun main() {
Kweb(port = 2395) {
doc.body.new {
val input: InputElement = input()
input.on.submit {
GlobalScope.launch {
val value = input.getValue().await()
println("Value: $value")
}
}
}
}
}
Note that input.getValue() returns a `CompletableFuture<String> <https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html>`_.
This is because it can take up to several hundred milliseconds to retrieve from the browser, and we don't want the application
Expand Down

0 comments on commit 6115191

Please sign in to comment.