diff options
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt | 12 | ||||
-rw-r--r-- | src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt | 2 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt index f71cee9f..99c8abf4 100644 --- a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt +++ b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt @@ -42,8 +42,8 @@ import pl.treksoft.kvision.panel.VPanel */ class DataContainer<M, C : Component>( private val model: ObservableList<M>, - private val binding: (Int) -> C, - private val filter: ((Int) -> Boolean)? = null, + private val binding: (Int, M) -> C, + private val filter: ((Int, M) -> Boolean)? = null, private val child: Container = VPanel(), init: (DataContainer<M, C>.() -> Unit)? = null ) : @@ -106,10 +106,10 @@ class DataContainer<M, C : Component>( child.removeAll() val indexed = model.mapIndexed { index, m -> index to m } val children = if (filter != null) { - indexed.filter { p -> filter.invoke(p.first) } + indexed.filter { p -> filter.invoke(p.first, p.second) } } else { indexed - }.map { p -> binding(p.first) } + }.map { p -> binding(p.first, p.second) } child.addAll(children) } onUpdateHandler?.invoke() @@ -142,8 +142,8 @@ class DataContainer<M, C : Component>( */ fun <M, C : Component> Container.dataContainer( model: ObservableList<M>, - binding: (Int) -> C, - filter: ((Int) -> Boolean)? = null, + binding: (Int, M) -> C, + filter: ((Int, M) -> Boolean)? = null, child: Container = VPanel(), init: (DataContainer<M, C>.() -> Unit)? = null ): DataContainer<M, C> { 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 809f5880..9e5c769f 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt @@ -42,7 +42,7 @@ class DataContainerSpec : DomSpec { } val model = observableListOf(Model("First"), Model("Second")) - val container = DataContainer(model, { index -> Label(model[index].value) }) + val container = DataContainer(model, { _, m -> Label(m.value) }) root.add(container) val element = document.getElementById("test") assertEqualsHtml( |