diff options
Diffstat (limited to 'src/main/kotlin/pl')
-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() |