From b095a2ff0284cb641cd3c7eb5cba09923304c55f Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Wed, 31 Jan 2018 00:08:01 +0100 Subject: Data container update handler --- src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt | 12 ++++++++++++ src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt | 1 + 2 files changed, 13 insertions(+) diff --git a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt index 2c87daea..6f9dfaeb 100644 --- a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt +++ b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt @@ -20,6 +20,8 @@ class DataContainer( child.visible = value } + internal var onUpdateHandler: (() -> Unit)? = null + init { child.parent = this model.onUpdate += { _ -> @@ -64,6 +66,16 @@ class DataContainer( child.removeAll() child.addAll(model.mapIndexed { index, _ -> binding(index) }) } + onUpdateHandler?.invoke() + } + + fun onUpdate(handler: () -> Unit): DataContainer { + onUpdateHandler = handler + return this } + fun clearOnUpdate(): DataContainer { + onUpdateHandler = null + return this + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt b/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt index 62f8c239..0367633c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt +++ b/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt @@ -54,6 +54,7 @@ interface BtOn : On { var hideBsDateTime: ((KvEvent) -> kotlin.Unit)? var onMinBsSpinner: ((KvEvent) -> kotlin.Unit)? var onMaxBsSpinner: ((KvEvent) -> kotlin.Unit)? + var updateModel: ((KvEvent) -> kotlin.Unit)? } interface SnOn : BtOn { -- cgit