diff --git a/build.gradle b/build.gradle index a25b5ca..cbdd463 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/src/main/kotlin/nl/astraeus/komp/KompElement.kt b/src/main/kotlin/nl/astraeus/komp/KompElement.kt index 8ba9e01..98fe23d 100644 --- a/src/main/kotlin/nl/astraeus/komp/KompElement.kt +++ b/src/main/kotlin/nl/astraeus/komp/KompElement.kt @@ -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? = null, + var attributes: MutableMap? = null, val children: MutableList? = null, val events: MutableMap 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 { 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 { } } - -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) { - val test = KompTest() - - println(test.create()) - - Komponent.create(document.body!!, KompTest()) -} -*/ diff --git a/src/main/kotlin/nl/astraeus/komp/Komponent.kt b/src/main/kotlin/nl/astraeus/komp/Komponent.kt index c4db474..afb038a 100644 --- a/src/main/kotlin/nl/astraeus/komp/Komponent.kt +++ b/src/main/kotlin/nl/astraeus/komp/Komponent.kt @@ -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 {