Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
misc stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Aug 5, 2018
1 parent 5f1e85c commit 89a9c82
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 8 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ allprojects {
}

buildscript {
ext.kotlin_version = '1.2.51'
ext.dokka_version = '0.9.15'
ext.kotlin_version = '1.2.60'
ext.dokka_version = '0.9.17'
ext.ktor_version = '0.9.3'

repositories {
Expand All @@ -35,7 +35,7 @@ buildscript {
}

group 'io.kweb'
version '0.3.3'
version '0.3.5'

apply plugin: 'java'

Expand Down
10 changes: 6 additions & 4 deletions src/main/kotlin/io/kweb/demos/todo/todoApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ fun main(args: Array<String>) {

/** A KVar is similar to an AtomicReference in the standard Java
Library, but which supports the observer pattern and `map`
semantics. Here I set it to the current URL of the page. This
will update automatically the page's URL changes, and can be
modified to update the page's URL, as you'll see below. */
semantics. Here I set it to the current URL of the page.
This will update automatically if the page's URL changes, and
if it is modified, the page's URL will change and the DOM will
re-render _without_ a page reload. Yes, seriously. */
val url: KVar<URL> = doc.receiver.url(simpleUrlParser)

/** s.content uses the semanticUIPlugin to use the excellent
Expand All @@ -67,7 +69,7 @@ fun main(args: Array<String>) {
specific part of the page must be re-rendered if
url.path[1] changes, which is very convenient
for the developer in comparison to other frameworks,
while being efficient under-the-hood. */
while minimizing server-browser chatter. */
render(url.path[1]) { listId ->
try {
/** Here I use the same render mechanism to tie DOM
Expand Down
15 changes: 15 additions & 0 deletions src/main/kotlin/io/kweb/dom/element/events/ONImmediateReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ import java.util.concurrent.ConcurrentHashMap
import kotlin.reflect.KClass
import kotlin.reflect.full.memberProperties

/**s
* *Warning:* Do not use this before familiarizing yourself with the information below.
*
* Pro:
* * Executes immediately, without any need for a server round-trip
* Con:
* * What you can do in the callback shouldn't rely on and _certainly_ shouldn't modify any server-side state. It's
* use should probably be limited to cosmetic UI cues like spinners. If you do the results could be very
* unpredictable, and may cause bugs that are difficult to diagnose.
*
* The reason is that the callback is actually only executed once. Any instructions to the browser are recorded
* and will simply be re-executed by the browser whenever this event occurs. This neat trick is how we avoid
* a server round-trip, but the price is additional caution about how we use it.
*/

@KWebDSL
open class ONImmediateReceiver(internal val parent: Element) : Element(parent) {

Expand Down
25 changes: 24 additions & 1 deletion src/main/kotlin/io/kweb/dom/element/events/on.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,30 @@ import io.kweb.dom.element.Element
* Created by ian on 1/13/17.
*/


/**
* Add an event callback to the `Element` that will be triggered on the server.
*
* Pro:
* * Can do anything it wishes in the callback, including modifying server state.
* Con:
* * Slight delay due to server-round trip for any DOM modifications in response to the event
*/
val Element.on: ONReceiver get() = ONReceiver(this)

/**
* Add an event callback to the `Element` that will be triggered within the browser.
*
* *Warning:* Do not use this before familiarizing yourself with the information below.
*
* Pro:
* * Executes immediately, without any need for a server round-trip
* Con:
* * What you can do in the callback shouldn't rely on and _certainly_ shouldn't modify any server-side state. It's
* use should probably be limited to cosmetic UI cues like spinners. If you do the results could be very
* unpredictable, and may cause bugs that are difficult to diagnose.
*
* The reason is that the callback is actually only executed once. Any instructions to the browser are recorded
* and will simply be re-executed by the browser whenever this event occurs. This neat trick is how we avoid
* a server round-trip, but the price is additional caution about how we use it.
*/
val Element.onImmediate : ONImmediateReceiver get() = ONImmediateReceiver(this)
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}

val copy : SemanticUIClasses get() {
classes("copy")
return this
}

val column : SemanticUIClasses get() {
classes("column")
return this
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/io/kweb/state/state.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ open class KVal<T : Any?>(value: T) {
listeners.remove(handle)
}

// TODO: A cachetime could be specified, to limit recalculation, could be quite broadly useful for expensive
// mappings
fun <O : Any> map(mapper: (T) -> O): KVal<O> {
if (isClosed) {
throw IllegalStateException("Mapping an already closed KVar")
Expand Down

0 comments on commit 89a9c82

Please sign in to comment.