Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of CMP-6802 #5150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AnonymousObjectsInComposable {
content.Abc()
}

assertEquals("<div>Abc</div>", document.body!!.firstElementChild!!.outerHTML)
assertEquals("<div>Abc</div>", document.body!!.lastElementChild!!.outerHTML)
}

@Test
Expand All @@ -30,7 +30,7 @@ class AnonymousObjectsInComposable {
HasLocalClassWithComposable()
}

assertEquals("<div>Abc2</div>", document.body!!.firstElementChild!!.outerHTML)
assertEquals("<div>Abc2</div>", document.body!!.lastElementChild!!.outerHTML)
}

@Test
Expand All @@ -41,7 +41,7 @@ class AnonymousObjectsInComposable {
TestConstructor { return@TestConstructor 111 }.otherComposable!!.invoke()
}

assertEquals("<div>Abc223-111</div>", document.body!!.firstElementChild!!.outerHTML)
assertEquals("<div>Abc223-111</div>", document.body!!.lastElementChild!!.outerHTML)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ComposableLambdaCalls {
}
}

assertEquals("<div>SomeText</div>", document.body!!.firstElementChild!!.outerHTML)
assertEquals("<div>SomeText</div>", document.body!!.lastElementChild!!.outerHTML)
}

@Test
Expand All @@ -36,7 +36,7 @@ class ComposableLambdaCalls {
}
}

assertEquals("<div>Text1</div>", document.body!!.firstElementChild!!.outerHTML)
assertEquals("<div>Text1</div>", document.body!!.lastElementChild!!.outerHTML)
}

@Test
Expand All @@ -51,7 +51,7 @@ class ComposableLambdaCalls {
}
}

assertEquals("<div>TextA</div>", document.body!!.firstElementChild!!.outerHTML)
assertEquals("<div>TextA</div>", document.body!!.lastElementChild!!.outerHTML)
}

@Test
Expand All @@ -64,7 +64,7 @@ class ComposableLambdaCalls {
}
}

assertEquals("<div></div>", document.body!!.firstElementChild!!.outerHTML)
assertEquals("<div></div>", document.body!!.lastElementChild!!.outerHTML)
}

@Test
Expand All @@ -84,7 +84,7 @@ class ComposableLambdaCalls {
}
}

assertEquals("<div></div>", document.body!!.firstElementChild!!.outerHTML)
assertEquals("<div></div>", document.body!!.lastElementChild!!.outerHTML)
assertEquals(false, someIntInvoked, message = "someInt() should never be invoked as `l` is null")
}

Expand All @@ -107,7 +107,7 @@ class ComposableLambdaCalls {
}
}

assertEquals("<div>Text10</div>", document.body!!.firstElementChild!!.outerHTML)
assertEquals("<div>Text10</div>", document.body!!.lastElementChild!!.outerHTML)
assertEquals(true, someIntInvoked)
}

Expand All @@ -123,7 +123,7 @@ class ComposableLambdaCalls {
}
}

assertEquals("<div>Text-SomeText</div>", document.body!!.firstElementChild!!.outerHTML)
assertEquals("<div>Text-SomeText</div>", document.body!!.lastElementChild!!.outerHTML)
}

@Test
Expand All @@ -136,6 +136,6 @@ class ComposableLambdaCalls {
}
}

assertEquals("<div>SuperText</div>", document.body!!.firstElementChild!!.outerHTML)
assertEquals("<div>SuperText</div>", document.body!!.lastElementChild!!.outerHTML)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DomApplier(

override fun onClear() {
// or current.node.clear()?; in all examples it calls 'clear' on the root
root.node.clear()
root.clear()
}
}

Expand All @@ -41,19 +41,25 @@ interface NamedEventListener : EventListener {

@ComposeWebInternalApi
open class DomNodeWrapper(open val node: Node) {
private val knownNodes: MutableList<DomNodeWrapper> = mutableListOf<DomNodeWrapper>()

fun insert(index: Int, nodeWrapper: DomNodeWrapper) {
val length = node.childNodes.length
val length = knownNodes.size
if (index < length) {
node.insertBefore(nodeWrapper.node, node.childNodes[index]!!)
val nodeOnIndex = knownNodes[index]
knownNodes.add(index, nodeWrapper)
node.insertBefore(nodeWrapper.node, nodeOnIndex.node)
} else {
knownNodes.add(nodeWrapper)

node.appendChild(nodeWrapper.node)
}
}

fun remove(index: Int, count: Int) {
repeat(count) {
node.removeChild(node.childNodes[index]!!)
val nodeToRemove = knownNodes.removeAt(index)
node.removeChild(nodeToRemove.node)
}
}

Expand All @@ -67,8 +73,20 @@ open class DomNodeWrapper(open val node: Node) {
val fromIndex = if (from > to) from + i else from
val toIndex = if (from > to) to + i else to + count - 2

val child = node.removeChild(node.childNodes[fromIndex]!!)
node.insertBefore(child, node.childNodes[toIndex]!!)
val nodeOnIndex = knownNodes[toIndex]

val nodeToMove = knownNodes.removeAt(fromIndex)
node.removeChild(nodeToMove.node)

knownNodes.add(toIndex, nodeToMove)
node.insertBefore(nodeToMove.node, nodeOnIndex.node)
}
}
}

internal fun clear() {
knownNodes.forEach {
node.removeChild(it.node)
}
knownNodes.clear()
}
}