aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-10-13 00:05:57 +0200
committerRobert Jaros <rjaros@finn.pl>2019-10-13 00:05:57 +0200
commite84227897eac9d90e79c5ba5ae775eac1085ea64 (patch)
treeac5d10f54b37aeaaedad482f5c591816818d9333
parent32551e8918b22762c067a895382a4faee53b9003 (diff)
downloadkvision-e84227897eac9d90e79c5ba5ae775eac1085ea64.tar.gz
kvision-e84227897eac9d90e79c5ba5ae775eac1085ea64.tar.bz2
kvision-e84227897eac9d90e79c5ba5ae775eac1085ea64.zip
Move ObservableList class from utils to state package and implement ObservableState interface.
-rw-r--r--kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt2
-rw-r--r--kvision-modules/kvision-datacontainer/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt2
-rw-r--r--kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt2
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/state/ObservableList.kt (renamed from src/main/kotlin/pl/treksoft/kvision/utils/ObservableList.kt)13
4 files changed, 12 insertions, 7 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 cb360982..24d8b974 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
@@ -26,7 +26,7 @@ import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.Widget
import pl.treksoft.kvision.panel.VPanel
-import pl.treksoft.kvision.utils.ObservableList
+import pl.treksoft.kvision.state.ObservableList
/**
* Sorter types.
diff --git a/kvision-modules/kvision-datacontainer/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt b/kvision-modules/kvision-datacontainer/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt
index 3904fab7..92661203 100644
--- a/kvision-modules/kvision-datacontainer/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt
+++ b/kvision-modules/kvision-datacontainer/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt
@@ -26,7 +26,7 @@ import pl.treksoft.kvision.data.DataContainer
import pl.treksoft.kvision.html.Span
import pl.treksoft.kvision.panel.Root
import pl.treksoft.kvision.panel.VPanel
-import pl.treksoft.kvision.utils.observableListOf
+import pl.treksoft.kvision.state.observableListOf
import test.pl.treksoft.kvision.DomSpec
import kotlin.browser.document
import kotlin.test.Test
diff --git a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt
index da1f48de..16638012 100644
--- a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt
+++ b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt
@@ -29,8 +29,8 @@ import pl.treksoft.kvision.core.StringBoolPair
import pl.treksoft.kvision.core.Widget
import pl.treksoft.kvision.i18n.I18n
import pl.treksoft.kvision.redux.ReduxStore
+import pl.treksoft.kvision.state.ObservableList
import pl.treksoft.kvision.table.TableType
-import pl.treksoft.kvision.utils.ObservableList
import pl.treksoft.kvision.utils.createInstance
import pl.treksoft.kvision.utils.obj
import pl.treksoft.kvision.utils.syncWithList
diff --git a/src/main/kotlin/pl/treksoft/kvision/utils/ObservableList.kt b/src/main/kotlin/pl/treksoft/kvision/state/ObservableList.kt
index bfd018e0..92109814 100644
--- a/src/main/kotlin/pl/treksoft/kvision/utils/ObservableList.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/state/ObservableList.kt
@@ -19,13 +19,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
-package pl.treksoft.kvision.utils
+package pl.treksoft.kvision.state
/**
* Observable list interface.
*/
-interface ObservableList<T> : MutableList<T> {
+interface ObservableList<T> : MutableList<T>, ObservableState<List<T>> {
val onUpdate: MutableCollection<(MutableList<T>) -> Unit>
}
@@ -33,7 +32,13 @@ interface ObservableList<T> : MutableList<T> {
* Simple observable list implementation.
*/
@Suppress("TooManyFunctions")
-class ObservableListWrapper<T>(val mutableList: MutableList<T> = mutableListOf()) : MutableList<T>, ObservableList<T> {
+class ObservableListWrapper<T>(val mutableList: MutableList<T> = mutableListOf()) : MutableList<T>, ObservableList<T>,
+ ObservableState<List<T>> {
+
+ override fun subscribe(observer: (List<T>) -> Unit) {
+ onUpdate += observer
+ observer(this)
+ }
override val onUpdate: MutableCollection<(MutableList<T>) -> Unit> = mutableListOf()