diff --git a/build.gradle b/build.gradle
index efa0f3d..8d235bb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,8 +19,12 @@
mavenCentral()
}
+ext {
+ kotlin_version = '1.1.4-2'
+}
+
buildscript {
- ext.kotlin_version = '1.1.4'
+ ext.kotlin_version = '1.1.4-2'
repositories {
maven {
url "http://nexus.astraeus.nl/nexus/content/groups/public"
@@ -34,7 +38,7 @@
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
- compile 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.2'
+ compile 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.4'
}
compileKotlin2Js {
diff --git a/build.gradle b/build.gradle
index efa0f3d..8d235bb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,8 +19,12 @@
mavenCentral()
}
+ext {
+ kotlin_version = '1.1.4-2'
+}
+
buildscript {
- ext.kotlin_version = '1.1.4'
+ ext.kotlin_version = '1.1.4-2'
repositories {
maven {
url "http://nexus.astraeus.nl/nexus/content/groups/public"
@@ -34,7 +38,7 @@
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
- compile 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.2'
+ compile 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.4'
}
compileKotlin2Js {
diff --git a/komp.iml b/komp.iml
index a88fd57..2ad513e 100644
--- a/komp.iml
+++ b/komp.iml
@@ -22,6 +22,7 @@
+
@@ -44,7 +45,7 @@
-
+
diff --git a/build.gradle b/build.gradle
index efa0f3d..8d235bb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,8 +19,12 @@
mavenCentral()
}
+ext {
+ kotlin_version = '1.1.4-2'
+}
+
buildscript {
- ext.kotlin_version = '1.1.4'
+ ext.kotlin_version = '1.1.4-2'
repositories {
maven {
url "http://nexus.astraeus.nl/nexus/content/groups/public"
@@ -34,7 +38,7 @@
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
- compile 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.2'
+ compile 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.4'
}
compileKotlin2Js {
diff --git a/komp.iml b/komp.iml
index a88fd57..2ad513e 100644
--- a/komp.iml
+++ b/komp.iml
@@ -22,6 +22,7 @@
+
@@ -44,7 +45,7 @@
-
+
diff --git a/komp.ipr b/komp.ipr
index f46dbaf..2dccbec 100644
--- a/komp.ipr
+++ b/komp.ipr
@@ -139,13 +139,13 @@
-
+
-
+
-
+
diff --git a/build.gradle b/build.gradle
index efa0f3d..8d235bb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,8 +19,12 @@
mavenCentral()
}
+ext {
+ kotlin_version = '1.1.4-2'
+}
+
buildscript {
- ext.kotlin_version = '1.1.4'
+ ext.kotlin_version = '1.1.4-2'
repositories {
maven {
url "http://nexus.astraeus.nl/nexus/content/groups/public"
@@ -34,7 +38,7 @@
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
- compile 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.2'
+ compile 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.4'
}
compileKotlin2Js {
diff --git a/komp.iml b/komp.iml
index a88fd57..2ad513e 100644
--- a/komp.iml
+++ b/komp.iml
@@ -22,6 +22,7 @@
+
@@ -44,7 +45,7 @@
-
+
diff --git a/komp.ipr b/komp.ipr
index f46dbaf..2dccbec 100644
--- a/komp.ipr
+++ b/komp.ipr
@@ -139,13 +139,13 @@
-
+
-
+
-
+
diff --git a/src/main/kotlin/nl/astraeus/komp/DomDiff.kt b/src/main/kotlin/nl/astraeus/komp/DomDiff.kt
index 7edd6c7..52cb308 100644
--- a/src/main/kotlin/nl/astraeus/komp/DomDiff.kt
+++ b/src/main/kotlin/nl/astraeus/komp/DomDiff.kt
@@ -1,6 +1,7 @@
package nl.astraeus.komp
-import org.w3c.dom.HTMLElement
+import org.w3c.dom.Element
+import org.w3c.dom.Node
import org.w3c.dom.get
/**
@@ -11,23 +12,21 @@
object DomDiffer {
- fun replaceDiff(newElement: HTMLElement, oldElement: HTMLElement): HTMLElement {
- println("CHECK $newElement -> $oldElement")
- if (!match(newElement, oldElement)) {
- println("no match, replace")
-
+ fun replaceDiff(newElement: Element, oldElement: Element): Element {
+ if (!newElement.isEqualNode(oldElement)) {
replaceNode(newElement, oldElement)
return newElement
} else {
- println("check children")
// think of the children!
- for (index in 0 until newElement.childElementCount) {
+ for (index in 0 until newElement.children.length) {
val newChild = newElement.children[index]
val oldChild = oldElement.children[index]
- if (newChild is HTMLElement && oldChild is HTMLElement) {
+ if (newChild is Element && oldChild is Element) {
replaceDiff(newChild, oldChild)
+ } else {
+ throw IllegalStateException("Children are not nodes! $newChild, $oldChild")
}
}
@@ -35,39 +34,10 @@
}
}
- private fun replaceNode(newElement: HTMLElement, oldElement: HTMLElement) {
- val parent = oldElement.parentElement
+ private fun replaceNode(newElement: Node, oldElement: Node) {
+ val parent = oldElement.parentElement ?: throw IllegalStateException("oldElement has no parent! $oldElement")
- parent?.replaceChild(newElement, oldElement)
- }
-
- fun match(newElement: HTMLElement, oldElement: HTMLElement): Boolean {
- var result = true
-
- result = result && newElement.namespaceURI == oldElement.namespaceURI
- result = result && newElement.nodeName == oldElement.nodeName
- result = result && newElement.childElementCount == oldElement.childElementCount
-
- val newAttr = newElement.attributes
- val oldAttr = oldElement.attributes
-
- result = result && newAttr.length == oldAttr.length
-
- if (result) {
- for (index in 0 until newAttr.length) {
- val attr = newAttr[index]
-
- if (attr != null) {
- result = result && newAttr.getNamedItem(attr.name)?.name == oldAttr.getNamedItem(attr.name)?.name
- result = result && newAttr.getNamedItem(attr.name)?.value == oldAttr.getNamedItem(attr.name)?.value
- }
- if (!result) {
- break
- }
- }
- }
-
- return result
+ parent.replaceChild(newElement, oldElement)
}
}
diff --git a/build.gradle b/build.gradle
index efa0f3d..8d235bb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,8 +19,12 @@
mavenCentral()
}
+ext {
+ kotlin_version = '1.1.4-2'
+}
+
buildscript {
- ext.kotlin_version = '1.1.4'
+ ext.kotlin_version = '1.1.4-2'
repositories {
maven {
url "http://nexus.astraeus.nl/nexus/content/groups/public"
@@ -34,7 +38,7 @@
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
- compile 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.2'
+ compile 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.4'
}
compileKotlin2Js {
diff --git a/komp.iml b/komp.iml
index a88fd57..2ad513e 100644
--- a/komp.iml
+++ b/komp.iml
@@ -22,6 +22,7 @@
+
@@ -44,7 +45,7 @@
-
+
diff --git a/komp.ipr b/komp.ipr
index f46dbaf..2dccbec 100644
--- a/komp.ipr
+++ b/komp.ipr
@@ -139,13 +139,13 @@
-
+
-
+
-
+
diff --git a/src/main/kotlin/nl/astraeus/komp/DomDiff.kt b/src/main/kotlin/nl/astraeus/komp/DomDiff.kt
index 7edd6c7..52cb308 100644
--- a/src/main/kotlin/nl/astraeus/komp/DomDiff.kt
+++ b/src/main/kotlin/nl/astraeus/komp/DomDiff.kt
@@ -1,6 +1,7 @@
package nl.astraeus.komp
-import org.w3c.dom.HTMLElement
+import org.w3c.dom.Element
+import org.w3c.dom.Node
import org.w3c.dom.get
/**
@@ -11,23 +12,21 @@
object DomDiffer {
- fun replaceDiff(newElement: HTMLElement, oldElement: HTMLElement): HTMLElement {
- println("CHECK $newElement -> $oldElement")
- if (!match(newElement, oldElement)) {
- println("no match, replace")
-
+ fun replaceDiff(newElement: Element, oldElement: Element): Element {
+ if (!newElement.isEqualNode(oldElement)) {
replaceNode(newElement, oldElement)
return newElement
} else {
- println("check children")
// think of the children!
- for (index in 0 until newElement.childElementCount) {
+ for (index in 0 until newElement.children.length) {
val newChild = newElement.children[index]
val oldChild = oldElement.children[index]
- if (newChild is HTMLElement && oldChild is HTMLElement) {
+ if (newChild is Element && oldChild is Element) {
replaceDiff(newChild, oldChild)
+ } else {
+ throw IllegalStateException("Children are not nodes! $newChild, $oldChild")
}
}
@@ -35,39 +34,10 @@
}
}
- private fun replaceNode(newElement: HTMLElement, oldElement: HTMLElement) {
- val parent = oldElement.parentElement
+ private fun replaceNode(newElement: Node, oldElement: Node) {
+ val parent = oldElement.parentElement ?: throw IllegalStateException("oldElement has no parent! $oldElement")
- parent?.replaceChild(newElement, oldElement)
- }
-
- fun match(newElement: HTMLElement, oldElement: HTMLElement): Boolean {
- var result = true
-
- result = result && newElement.namespaceURI == oldElement.namespaceURI
- result = result && newElement.nodeName == oldElement.nodeName
- result = result && newElement.childElementCount == oldElement.childElementCount
-
- val newAttr = newElement.attributes
- val oldAttr = oldElement.attributes
-
- result = result && newAttr.length == oldAttr.length
-
- if (result) {
- for (index in 0 until newAttr.length) {
- val attr = newAttr[index]
-
- if (attr != null) {
- result = result && newAttr.getNamedItem(attr.name)?.name == oldAttr.getNamedItem(attr.name)?.name
- result = result && newAttr.getNamedItem(attr.name)?.value == oldAttr.getNamedItem(attr.name)?.value
- }
- if (!result) {
- break
- }
- }
- }
-
- return result
+ parent.replaceChild(newElement, oldElement)
}
}
diff --git a/src/main/kotlin/nl/astraeus/komp/Komponent.kt b/src/main/kotlin/nl/astraeus/komp/Komponent.kt
index 9c38b0a..c5c78bd 100644
--- a/src/main/kotlin/nl/astraeus/komp/Komponent.kt
+++ b/src/main/kotlin/nl/astraeus/komp/Komponent.kt
@@ -5,6 +5,7 @@
import kotlinx.html.SPAN
import kotlinx.html.TagConsumer
import kotlinx.html.dom.create
+import org.w3c.dom.Element
import org.w3c.dom.HTMLElement
import kotlin.browser.document
@@ -30,7 +31,7 @@
}
abstract class Komponent {
- var element: HTMLElement? = null
+ var element: Element? = null
var rendered = false
fun create(): HTMLElement {
@@ -65,7 +66,7 @@
companion object {
- private val elements: MutableMap = HashMap()
+ private val elements: MutableMap = HashMap()
private val elementList: MutableList = ArrayList()
fun define(element: HTMLElement, component: Komponent) {
@@ -86,7 +87,7 @@
elementList.add(component)
}
- fun remove(element: HTMLElement) {
+ fun remove(element: Element) {
val component = elements[element]
elements.remove(element)
@@ -107,7 +108,7 @@
refresh(component.element)
}
- fun refresh(element: HTMLElement?) {
+ fun refresh(element: Element?) {
if (element != null) {
elements[element]?.let {
//val parent = element.parentElement