diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-06-02 23:45:18 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-06-02 23:45:18 +0200 |
commit | b7901e371f148bedd105b1f91c5485ec6e9a2f48 (patch) | |
tree | 790259fc116d64049e906912926dcaa0003dca14 | |
parent | 769eb4cb7f44832b9e8ba48c84d900e13f06c851 (diff) | |
download | kvision-b7901e371f148bedd105b1f91c5485ec6e9a2f48.tar.gz kvision-b7901e371f148bedd105b1f91c5485ec6e9a2f48.tar.bz2 kvision-b7901e371f148bedd105b1f91c5485ec6e9a2f48.zip |
Add parameter of bind, for not removing children when binding component to the state
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/core/Widget.kt | 3 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt | 4 |
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) } /** |