diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-03-07 00:09:02 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-03-07 00:09:02 +0100 |
commit | 32ddb5789a4f9b644836d3a0cc2f9b14b37b5e5b (patch) | |
tree | b0ef6f63b0b0244432f68e026f36b053879d91dd | |
parent | c87e1851919c60d57aeb77809a94f589d537f827 (diff) | |
download | kvision-32ddb5789a4f9b644836d3a0cc2f9b14b37b5e5b.tar.gz kvision-32ddb5789a4f9b644836d3a0cc2f9b14b37b5e5b.tar.bz2 kvision-32ddb5789a4f9b644836d3a0cc2f9b14b37b5e5b.zip |
Add model parameter to DataContainer callback functions.
-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( |