diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-04-22 19:07:16 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-04-22 19:07:16 +0200 |
commit | 6f7736b85e0889aff26860e2960f52b301f460c5 (patch) | |
tree | db917dafd000cc622633dda422bbba91a4e0fcff | |
parent | 8d4f2f3a01b343e4e1d039aa78dbbcaa9f7dbb48 (diff) | |
download | kvision-6f7736b85e0889aff26860e2960f52b301f460c5.tar.gz kvision-6f7736b85e0889aff26860e2960f52b301f460c5.tar.bz2 kvision-6f7736b85e0889aff26860e2960f52b301f460c5.zip |
Allow more general model in the data container.
-rw-r--r-- | kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt b/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt index 69851b29..6c05da4b 100644 --- a/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt +++ b/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt @@ -37,13 +37,13 @@ enum class SorterType { } /** - * A container class with support for observable data model. + * A container class with support for mutable/observable data model. * * @constructor Creates DataContainer bound to given data model. * @param M data model type * @param C visual component type * @param CONT container type - * @param model data model of type *ObservableList<M>* + * @param model data model of type *MutableList<M>* * @param factory a function which creates component C from data model at given index * @param container internal container * @param containerAdd function to add component C to the internal container CONT @@ -53,8 +53,8 @@ enum class SorterType { * @param init an initializer extension function */ class DataContainer<M, C : Component, CONT : Container>( - private val model: ObservableList<M>, - private val factory: (M, Int, ObservableList<M>) -> C, + private val model: MutableList<M>, + private val factory: (M, Int, MutableList<M>) -> C, private val container: CONT, private val containerAdd: (CONT.(C, M) -> Unit)? = null, private val filter: ((M) -> Boolean)? = null, @@ -74,8 +74,10 @@ class DataContainer<M, C : Component, CONT : Container>( init { container.parent = this - model.onUpdate += { - update() + if (model is ObservableList) { + model.onUpdate += { + update() + } } update() @Suppress("LeakingThis") @@ -180,8 +182,8 @@ class DataContainer<M, C : Component, CONT : Container>( * It takes the same parameters as the constructor of the built component. */ fun <M, C : Component, CONT : Container> Container.dataContainer( - model: ObservableList<M>, - factory: (M, Int, ObservableList<M>) -> C, + model: MutableList<M>, + factory: (M, Int, MutableList<M>) -> C, container: CONT, containerAdd: (CONT.(C, M) -> Unit)? = null, filter: ((M) -> Boolean)? = null, @@ -200,8 +202,8 @@ class DataContainer<M, C : Component, CONT : Container>( * It takes the same parameters as the constructor of the built component. */ fun <M, C : Component> Container.dataContainer( - model: ObservableList<M>, - factory: (M, Int, ObservableList<M>) -> C, + model: MutableList<M>, + factory: (M, Int, MutableList<M>) -> C, containerAdd: (VPanel.(C, M) -> Unit)? = null, filter: ((M) -> Boolean)? = null, sorter: ((M) -> Comparable<*>?)? = null, |