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 9441d84 commit 647cf07
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions dom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Working with the DOM
====================

Modifying the DOM
-------------------
-----------------

The DOM is built starting with an element, typically the BodyElement which is obtained easily as follows:

Expand Down Expand Up @@ -32,12 +32,37 @@ As you can see, it's easy to set the text of an element, you can also modify its

.. code-block:: kotlin
clickMe.setAttribute("class", "nicebutton")
clickMe.setAttribute("class", "bigbutton")
Or delete it:

.. code-block:: kotlin
clickMe.delete()
Reading the DOM
---------------

(TODO) Document reading values from the DOM tree
You can read values from the DOM too:

.. code-block:: kotlin
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())
}
}
}
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 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()*.

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

0 comments on commit 647cf07

Please sign in to comment.