diff --git a/src/main/kotlin/nl/astraeus/komp/DomDiff.kt b/src/main/kotlin/nl/astraeus/komp/DomDiff.kt index eb94855..7edd6c7 100644 --- a/src/main/kotlin/nl/astraeus/komp/DomDiff.kt +++ b/src/main/kotlin/nl/astraeus/komp/DomDiff.kt @@ -11,10 +11,16 @@ object DomDiffer { - fun replaceDiff(newElement: HTMLElement, oldElement: HTMLElement) { + fun replaceDiff(newElement: HTMLElement, oldElement: HTMLElement): HTMLElement { + println("CHECK $newElement -> $oldElement") if (!match(newElement, oldElement)) { + println("no match, replace") + replaceNode(newElement, oldElement) + + return newElement } else { + println("check children") // think of the children! for (index in 0 until newElement.childElementCount) { val newChild = newElement.children[index] @@ -24,6 +30,8 @@ replaceDiff(newChild, oldChild) } } + + return oldElement } } diff --git a/src/main/kotlin/nl/astraeus/komp/DomDiff.kt b/src/main/kotlin/nl/astraeus/komp/DomDiff.kt index eb94855..7edd6c7 100644 --- a/src/main/kotlin/nl/astraeus/komp/DomDiff.kt +++ b/src/main/kotlin/nl/astraeus/komp/DomDiff.kt @@ -11,10 +11,16 @@ object DomDiffer { - fun replaceDiff(newElement: HTMLElement, oldElement: HTMLElement) { + fun replaceDiff(newElement: HTMLElement, oldElement: HTMLElement): HTMLElement { + println("CHECK $newElement -> $oldElement") if (!match(newElement, oldElement)) { + println("no match, replace") + replaceNode(newElement, oldElement) + + return newElement } else { + println("check children") // think of the children! for (index in 0 until newElement.childElementCount) { val newChild = newElement.children[index] @@ -24,6 +30,8 @@ replaceDiff(newChild, oldChild) } } + + return oldElement } } diff --git a/src/main/kotlin/nl/astraeus/komp/Komponent.kt b/src/main/kotlin/nl/astraeus/komp/Komponent.kt index 4692447..9c38b0a 100644 --- a/src/main/kotlin/nl/astraeus/komp/Komponent.kt +++ b/src/main/kotlin/nl/astraeus/komp/Komponent.kt @@ -110,11 +110,16 @@ fun refresh(element: HTMLElement?) { if (element != null) { elements[element]?.let { - val parent = element.parentElement + //val parent = element.parentElement val newElement = it.create() - parent?.replaceChild(newElement, element) - //DomDiffer.replaceDiff(newElement, element) + //parent?.replaceChild(newElement, element) + val replacedElement = DomDiffer.replaceDiff(newElement, element) + + it.element = replacedElement + + elements.remove(replacedElement) + elements[replacedElement] = it } } }