aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-03-07 19:02:54 +0100
committerRobert Jaros <rjaros@finn.pl>2018-03-07 19:02:54 +0100
commit457c34a66170b1b5d395bff24297958902a81de7 (patch)
tree3520af4b7dc9c4a3508ef75f2222566a53fe39cf /src/main/kotlin/pl/treksoft
parenta2be91f3b09a79759f4d9214e5df700a2939fa59 (diff)
downloadkvision-457c34a66170b1b5d395bff24297958902a81de7.tar.gz
kvision-457c34a66170b1b5d395bff24297958902a81de7.tar.bz2
kvision-457c34a66170b1b5d395bff24297958902a81de7.zip
Add index as mapping function parameter.
Diffstat (limited to 'src/main/kotlin/pl/treksoft')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt
index b8d13c77..80a05ba7 100644
--- a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt
@@ -45,7 +45,7 @@ class DataContainer<M, C : Component>(
private val model: ObservableList<M>,
private val factory: (Int, M) -> C,
private val filter: ((Int, M) -> Boolean)? = null,
- private val mapping: ((List<M>) -> List<M>)? = null,
+ private val mapping: ((List<Pair<Int, M>>) -> List<Pair<Int, M>>)? = null,
private val container: Container = VPanel(),
init: (DataContainer<M, C>.() -> Unit)? = null
) :
@@ -106,12 +106,12 @@ class DataContainer<M, C : Component>(
}
singleRender {
container.removeAll()
- val mapped = mapping?.invoke(model) ?: model
- val indexed = mapped.mapIndexed { index, m -> index to m }
+ val indexed = model.mapIndexed { index, m -> index to m }
+ val mapped = mapping?.invoke(indexed) ?: indexed
val children = if (filter != null) {
- indexed.filter { p -> filter.invoke(p.first, p.second) }
+ mapped.filter { p -> filter.invoke(p.first, p.second) }
} else {
- indexed
+ mapped
}.map { p -> factory(p.first, p.second) }
container.addAll(children)
}
@@ -147,7 +147,7 @@ class DataContainer<M, C : Component>(
model: ObservableList<M>,
factory: (Int, M) -> C,
filter: ((Int, M) -> Boolean)? = null,
- mapping: ((List<M>) -> List<M>)? = null,
+ mapping: ((List<Pair<Int, M>>) -> List<Pair<Int, M>>)? = null,
container: Container = VPanel(),
init: (DataContainer<M, C>.() -> Unit)? = null
): DataContainer<M, C> {