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

Commit

Permalink
misc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Dec 20, 2018
1 parent 647cf07 commit e3e44be
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions dom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@ You can read values from the DOM too:
doc.body.new {
val label = h1().text("What is your name?")
val clickMe = input(type = text, placeholder = "Enter your name")
clickMe.on.blur {
GlobalScope.launch {
label.text(clickMe.getValue().await())
}
val clickMe = input(type = text)
clickMe.setValue("Foo Bar")
GlobalScope.launch {
val v : String = clickMe.getValue().await()
label.text("Value: $v")
}
}
Notice that *clickMe.getValue() doesn't return a String, it returns a *CompletableFuture<String>.
This is because retrieving something from the DOM requires some communication with the browser and
will take some time - and we don't want to block while we wait.
This example is a little pointless since we're just setting the value and then immediately reading it, but it becomes
a lot more useful once you know how to attach event listeners to DOM elements.

This allows us to take advantage of Kotlin's `coroutines <https://kotlinlang.org/docs/reference/coroutines/basics.html>`_
functionality to make this fairly seamless to the programmer (using *GlobalScope.launch* and *await()*.
functionality to make this fairly seamless to the programmer (using *GlobalScope.launch* and *await()*).

Listening for events
--------------------
Expand Down

0 comments on commit e3e44be

Please sign in to comment.