Fix REPLACE logic

This commit is contained in:
2018-11-18 16:29:16 +01:00
parent 4d29114a15
commit 57d52cc441
2 changed files with 11 additions and 12 deletions

View File

@@ -163,12 +163,12 @@ class KompElement(
div.innerHTML = text 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) { for (index in 0 until div.childNodes.length) {
val node = div.childNodes[index]!! val node = div.childNodes[index]!!
console.log("$index -> ", node) //console.log("$index -> ", node)
if (node.isElement) { if (node.isElement) {
if (result != null) { if (result != null) {
@@ -181,7 +181,7 @@ class KompElement(
result ?: throw IllegalStateException("No element found in unsafe content! [$text]") result ?: throw IllegalStateException("No element found in unsafe content! [$text]")
} }
ElementType.TAG -> { ElementType.TAG -> {
var svg = text == "svg" val svg = text == "svg"
val result = if (svg) { val result = if (svg) {
document.createElementNS("http://www.w3.org/2000/svg", text) document.createElementNS("http://www.w3.org/2000/svg", text)
} else { } else {
@@ -294,7 +294,7 @@ class KompConsumer : TagConsumer<KompElement> {
} }
override fun onTagContentEntity(entity: Entities) { override fun onTagContentEntity(entity: Entities) {
console.log("KC.onTagContentEntity", entity) //console.log("KC.onTagContentEntity", entity)
} }
override fun onTagContentUnsafe(block: Unsafe.() -> Unit) { override fun onTagContentUnsafe(block: Unsafe.() -> Unit) {
@@ -303,12 +303,12 @@ class KompConsumer : TagConsumer<KompElement> {
block.invoke(txt) block.invoke(txt)
console.log("KC.onTagContentUnsafe", txt) //console.log("KC.onTagContentUnsafe", txt)
currentTag?.children?.add(KompElement(txt.text, ElementType.UNSAFE)) currentTag?.children?.add(KompElement(txt.text, ElementType.UNSAFE))
} }
override fun onTagEnd(tag: Tag) { override fun onTagEnd(tag: Tag) {
console.log("KC.onTagEnd", tag) //console.log("KC.onTagEnd", tag)
check(currentTag != null) check(currentTag != null)
check(currentTag?.children != null) check(currentTag?.children != null)
@@ -330,7 +330,7 @@ class KompConsumer : TagConsumer<KompElement> {
} }
override fun onTagStart(tag: Tag) { override fun onTagStart(tag: Tag) {
console.log("KC.onTagStart", tag) //console.log("KC.onTagStart", tag)
currentTag?.apply { currentTag?.apply {
stack.add(this) stack.add(this)
@@ -396,7 +396,7 @@ class KompTest : Komponent() {
onClickFunction = { onClickFunction = {
show = true show = true
console.log("show", this) //console.log("show", this)
update() update()
} }

View File

@@ -14,7 +14,7 @@ fun HtmlBlockTag.include(component: Komponent) {
} }
/* /*
newElement.komponent = it newElement.komponent = it
val kc = this.consumer val kc = this.consumer
val result = component.render(kc as KompConsumer) val result = component.render(kc as KompConsumer)
val element = result.create() val element = result.create()
@@ -176,12 +176,11 @@ abstract class Komponent {
val newElement = it.create() val newElement = it.create()
if (updateStrategy == UpdateStrategy.REPLACE) { if (updateStrategy == UpdateStrategy.REPLACE) {
replaceNode(newElement, element) //val replacedElement = replaceNode(newElement, element)
/*
val replacedElement = replaceNode(newElement, element) val replacedElement = replaceNode(newElement, element)
it.element = replacedElement it.element = replacedElement
elements[replacedElement] = it elements[replacedElement] = it
*/
} else { } else {
val kompElement = it.kompElement val kompElement = it.kompElement