aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
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.
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/state/ObservableList.kt (renamed from src/main/kotlin/pl/treksoft/kvision/utils/ObservableList.kt)13
1 files changed, 9 insertions, 4 deletions
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()