diff options
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt b/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt index 7df82adc..adb7d3be 100644 --- a/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt +++ b/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt @@ -22,8 +22,10 @@ class StateBinding<S : Any, CONT : Container, CONTENT>( private val factory: (CONT.(S) -> CONTENT) ) : Widget(setOf()) { + private val unsubscribe: () -> Unit + init { - observableState.subscribe { update(it) } + unsubscribe = observableState.subscribe { update(it) } } private var updateState: ((S, CONTENT) -> Unit)? = null @@ -51,6 +53,11 @@ class StateBinding<S : Any, CONT : Container, CONTENT>( this.updateState = updateState } + override fun dispose() { + unsubscribe() + super.dispose() + } + companion object { /** * DSL builder extension function. |