aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/pl/treksoft')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Widget.kt3
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt4
2 files changed, 5 insertions, 2 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
index 72c5699c..371b5a20 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
@@ -1019,11 +1019,12 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent(), Component
*/
internal fun <S, W : Widget> W.bindState(
observableState: ObservableState<S>,
+ removeChildren: Boolean = true,
factory: (W.(S) -> Unit)
): W {
val unsubscribe = observableState.subscribe {
this.singleRender {
- (this as? Container)?.removeAll()
+ if (removeChildren) (this as? Container)?.removeAll()
this.factory(it)
}
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt b/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt
index 6c8090b7..457af0e4 100644
--- a/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt
@@ -13,13 +13,15 @@ import pl.treksoft.kvision.core.Widget.Companion.bindState
* @param S the state type
* @param W the widget type
* @param observableState the state
+ * @param removeChildren remove all children of the component
* @param factory a function which re-creates the view based on the given state
*/
fun <S, W : Widget> W.bind(
observableState: ObservableState<S>,
+ removeChildren: Boolean = true,
factory: (W.(S) -> Unit)
): W {
- return this.bindState(observableState, factory)
+ return this.bindState(observableState, removeChildren, factory)
}
/**