Faster attribute handling

This commit is contained in:
2018-12-30 16:12:39 +01:00
parent 57d52cc441
commit 7c5415df0d
3 changed files with 4 additions and 87 deletions

View File

@@ -1,5 +1,5 @@
group 'nl.astraeus'
version '0.1.1-SNAPSHOT'
version '0.1.2-SNAPSHOT'
apply plugin: 'kotlin2js'
apply plugin: 'kotlin-dce-js'

View File

@@ -4,11 +4,6 @@ import kotlinx.html.Entities
import kotlinx.html.Tag
import kotlinx.html.TagConsumer
import kotlinx.html.Unsafe
import kotlinx.html.div
import kotlinx.html.h1
import kotlinx.html.hr
import kotlinx.html.js.onClickFunction
import kotlinx.html.span
import org.w3c.dom.Node
import org.w3c.dom.events.Event
import org.w3c.dom.get
@@ -32,7 +27,7 @@ class KompElement(
val type: ElementType,
val komponent: Komponent?,
var text: String,
val attributes: MutableMap<String, String>? = null,
var attributes: MutableMap<String, String>? = null,
val children: MutableList<KompElement>? = null,
val events: MutableMap<String, (Event) -> Unit>? = null
) {
@@ -221,7 +216,7 @@ class KompElement(
result.append("<")
}
result.append(text)
if (attributes != null) {
attributes?.also { attributes ->
for (entry in attributes.entries) {
result.append("\n")
result.append(indent)
@@ -338,9 +333,7 @@ class KompConsumer : TagConsumer<KompElement> {
currentTag = KompElement(tag.tagName, ElementType.TAG)
for (attr in tag.attributes.entries) {
currentTag?.attributes?.set(attr.key, attr.value)
}
currentTag?.attributes = tag.attributes
}
fun appendKomponent(komponent: Komponent) {
@@ -348,69 +341,3 @@ class KompConsumer : TagConsumer<KompElement> {
}
}
class KompTest : Komponent() {
var counter = 0
var show = false
var child: KompTest? = null
override fun render(consumer: KompConsumer) = consumer.div {
h1 {
+"Test"
}
hr { }
span {
+"Clicks $counter"
onClickFunction = {
println("click")
counter++
update()
}
}
if (show) {
hr {}
span {
+"Hide element"
onClickFunction = {
show = false
update()
}
}
if (child == null) {
child = KompTest()
}
include(child!!)
} else {
hr {}
span {
+"Show element"
onClickFunction = {
show = true
//console.log("show", this)
update()
}
}
}
}
}
/*
fun main(args: Array<String>) {
val test = KompTest()
println(test.create())
Komponent.create(document.body!!, KompTest())
}
*/

View File

@@ -12,16 +12,6 @@ fun HtmlBlockTag.include(component: Komponent) {
if (consumer is KompConsumer) {
consumer.appendKomponent(component)
}
/*
newElement.komponent = it
val kc = this.consumer
val result = component.render(kc as KompConsumer)
val element = result.create()
component.element = element
Komponent.define(element, component, result)
*/
}
enum class UpdateStrategy {