From 57d52cc4412ed3f8267297f72e748bca2752b1f5 Mon Sep 17 00:00:00 2001 From: rnentjes Date: Sun, 18 Nov 2018 16:29:16 +0100 Subject: [PATCH] Fix REPLACE logic --- src/main/kotlin/nl/astraeus/komp/KompElement.kt | 16 ++++++++-------- src/main/kotlin/nl/astraeus/komp/Komponent.kt | 7 +++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/nl/astraeus/komp/KompElement.kt b/src/main/kotlin/nl/astraeus/komp/KompElement.kt index 2accfcc..8ba9e01 100644 --- a/src/main/kotlin/nl/astraeus/komp/KompElement.kt +++ b/src/main/kotlin/nl/astraeus/komp/KompElement.kt @@ -163,12 +163,12 @@ class KompElement( div.innerHTML = text - console.log("div element with unsafe innerHTML", div) + //console.log("div element with unsafe innerHTML", div) for (index in 0 until div.childNodes.length) { val node = div.childNodes[index]!! - console.log("$index -> ", node) + //console.log("$index -> ", node) if (node.isElement) { if (result != null) { @@ -181,7 +181,7 @@ class KompElement( result ?: throw IllegalStateException("No element found in unsafe content! [$text]") } ElementType.TAG -> { - var svg = text == "svg" + val svg = text == "svg" val result = if (svg) { document.createElementNS("http://www.w3.org/2000/svg", text) } else { @@ -294,7 +294,7 @@ class KompConsumer : TagConsumer { } override fun onTagContentEntity(entity: Entities) { - console.log("KC.onTagContentEntity", entity) + //console.log("KC.onTagContentEntity", entity) } override fun onTagContentUnsafe(block: Unsafe.() -> Unit) { @@ -303,12 +303,12 @@ class KompConsumer : TagConsumer { block.invoke(txt) - console.log("KC.onTagContentUnsafe", txt) + //console.log("KC.onTagContentUnsafe", txt) currentTag?.children?.add(KompElement(txt.text, ElementType.UNSAFE)) } override fun onTagEnd(tag: Tag) { - console.log("KC.onTagEnd", tag) + //console.log("KC.onTagEnd", tag) check(currentTag != null) check(currentTag?.children != null) @@ -330,7 +330,7 @@ class KompConsumer : TagConsumer { } override fun onTagStart(tag: Tag) { - console.log("KC.onTagStart", tag) + //console.log("KC.onTagStart", tag) currentTag?.apply { stack.add(this) @@ -396,7 +396,7 @@ class KompTest : Komponent() { onClickFunction = { show = true - console.log("show", this) + //console.log("show", this) update() } diff --git a/src/main/kotlin/nl/astraeus/komp/Komponent.kt b/src/main/kotlin/nl/astraeus/komp/Komponent.kt index 89b19e1..c4db474 100644 --- a/src/main/kotlin/nl/astraeus/komp/Komponent.kt +++ b/src/main/kotlin/nl/astraeus/komp/Komponent.kt @@ -14,7 +14,7 @@ fun HtmlBlockTag.include(component: Komponent) { } /* - newElement.komponent = it + newElement.komponent = it val kc = this.consumer val result = component.render(kc as KompConsumer) val element = result.create() @@ -176,12 +176,11 @@ abstract class Komponent { val newElement = it.create() if (updateStrategy == UpdateStrategy.REPLACE) { - replaceNode(newElement, element) -/* + //val replacedElement = replaceNode(newElement, element) + val replacedElement = replaceNode(newElement, element) it.element = replacedElement elements[replacedElement] = it -*/ } else { val kompElement = it.kompElement