aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt6
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt2
2 files changed, 5 insertions, 3 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt
index 4dbceaea..32546bd5 100644
--- a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt
@@ -9,7 +9,7 @@ import pl.treksoft.kvision.panel.VPanel
class DataContainer<M : DataComponent, C : Widget>(
val model: ObservableList<M>,
- private val binding: (M, Int) -> C,
+ private val binding: (Int) -> C,
private val child: Container = VPanel()
) :
Widget(setOf()), Container, DataUpdatable {
@@ -56,11 +56,13 @@ class DataContainer<M : DataComponent, C : Widget>(
return this.child.renderVNode()
}
+ open fun get(index: Int) = model[index]
+
override fun update() {
model.forEach { it.container = this }
singleRender {
child.removeAll()
- child.addAll(model.mapIndexed { index, m -> binding(m, index) })
+ child.addAll(model.mapIndexed { index, _ -> binding(index) })
}
}
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt
index 30cf0db9..b4b1122f 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt
@@ -22,7 +22,7 @@ class DataContainerSpec : DomSpec {
}
val model = observableListOf(Model("First"), Model("Second"))
- val container = DataContainer(model, { element, _ -> Label(element.value) })
+ val container = DataContainer(model, { index -> Label(model[index].value) })
root.add(container)
val element = document.getElementById("test")
assertEquals(