Testing dom diffing
This commit is contained in:
@@ -11,10 +11,16 @@ import org.w3c.dom.get
|
|||||||
|
|
||||||
object DomDiffer {
|
object DomDiffer {
|
||||||
|
|
||||||
fun replaceDiff(newElement: HTMLElement, oldElement: HTMLElement) {
|
fun replaceDiff(newElement: HTMLElement, oldElement: HTMLElement): HTMLElement {
|
||||||
|
println("CHECK $newElement -> $oldElement")
|
||||||
if (!match(newElement, oldElement)) {
|
if (!match(newElement, oldElement)) {
|
||||||
|
println("no match, replace")
|
||||||
|
|
||||||
replaceNode(newElement, oldElement)
|
replaceNode(newElement, oldElement)
|
||||||
|
|
||||||
|
return newElement
|
||||||
} else {
|
} else {
|
||||||
|
println("check children")
|
||||||
// think of the children!
|
// think of the children!
|
||||||
for (index in 0 until newElement.childElementCount) {
|
for (index in 0 until newElement.childElementCount) {
|
||||||
val newChild = newElement.children[index]
|
val newChild = newElement.children[index]
|
||||||
@@ -24,6 +30,8 @@ object DomDiffer {
|
|||||||
replaceDiff(newChild, oldChild)
|
replaceDiff(newChild, oldChild)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return oldElement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,11 +110,16 @@ abstract class Komponent {
|
|||||||
fun refresh(element: HTMLElement?) {
|
fun refresh(element: HTMLElement?) {
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
elements[element]?.let {
|
elements[element]?.let {
|
||||||
val parent = element.parentElement
|
//val parent = element.parentElement
|
||||||
val newElement = it.create()
|
val newElement = it.create()
|
||||||
|
|
||||||
parent?.replaceChild(newElement, element)
|
//parent?.replaceChild(newElement, element)
|
||||||
//DomDiffer.replaceDiff(newElement, element)
|
val replacedElement = DomDiffer.replaceDiff(newElement, element)
|
||||||
|
|
||||||
|
it.element = replacedElement
|
||||||
|
|
||||||
|
elements.remove(replacedElement)
|
||||||
|
elements[replacedElement] = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user