Faster attribute handling
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
group 'nl.astraeus'
|
group 'nl.astraeus'
|
||||||
version '0.1.1-SNAPSHOT'
|
version '0.1.2-SNAPSHOT'
|
||||||
|
|
||||||
apply plugin: 'kotlin2js'
|
apply plugin: 'kotlin2js'
|
||||||
apply plugin: 'kotlin-dce-js'
|
apply plugin: 'kotlin-dce-js'
|
||||||
|
|||||||
@@ -4,11 +4,6 @@ import kotlinx.html.Entities
|
|||||||
import kotlinx.html.Tag
|
import kotlinx.html.Tag
|
||||||
import kotlinx.html.TagConsumer
|
import kotlinx.html.TagConsumer
|
||||||
import kotlinx.html.Unsafe
|
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.Node
|
||||||
import org.w3c.dom.events.Event
|
import org.w3c.dom.events.Event
|
||||||
import org.w3c.dom.get
|
import org.w3c.dom.get
|
||||||
@@ -32,7 +27,7 @@ class KompElement(
|
|||||||
val type: ElementType,
|
val type: ElementType,
|
||||||
val komponent: Komponent?,
|
val komponent: Komponent?,
|
||||||
var text: String,
|
var text: String,
|
||||||
val attributes: MutableMap<String, String>? = null,
|
var attributes: MutableMap<String, String>? = null,
|
||||||
val children: MutableList<KompElement>? = null,
|
val children: MutableList<KompElement>? = null,
|
||||||
val events: MutableMap<String, (Event) -> Unit>? = null
|
val events: MutableMap<String, (Event) -> Unit>? = null
|
||||||
) {
|
) {
|
||||||
@@ -221,7 +216,7 @@ class KompElement(
|
|||||||
result.append("<")
|
result.append("<")
|
||||||
}
|
}
|
||||||
result.append(text)
|
result.append(text)
|
||||||
if (attributes != null) {
|
attributes?.also { attributes ->
|
||||||
for (entry in attributes.entries) {
|
for (entry in attributes.entries) {
|
||||||
result.append("\n")
|
result.append("\n")
|
||||||
result.append(indent)
|
result.append(indent)
|
||||||
@@ -338,9 +333,7 @@ class KompConsumer : TagConsumer<KompElement> {
|
|||||||
|
|
||||||
currentTag = KompElement(tag.tagName, ElementType.TAG)
|
currentTag = KompElement(tag.tagName, ElementType.TAG)
|
||||||
|
|
||||||
for (attr in tag.attributes.entries) {
|
currentTag?.attributes = tag.attributes
|
||||||
currentTag?.attributes?.set(attr.key, attr.value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun appendKomponent(komponent: Komponent) {
|
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())
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -12,16 +12,6 @@ fun HtmlBlockTag.include(component: Komponent) {
|
|||||||
if (consumer is KompConsumer) {
|
if (consumer is KompConsumer) {
|
||||||
consumer.appendKomponent(component)
|
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 {
|
enum class UpdateStrategy {
|
||||||
|
|||||||
Reference in New Issue
Block a user