aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/state
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2020-05-03 22:43:53 +0200
committerRobert Jaros <rjaros@finn.pl>2020-05-03 22:43:53 +0200
commit0b349de3cc699b54b02d7177418c8cf155afe929 (patch)
tree3b01196a3e629e1b7437f7c7e5c8eb413a4ed937 /src/main/kotlin/pl/treksoft/kvision/state
parentd502659176e11f4b1d2294e536d9e3b66b72080c (diff)
downloadkvision-0b349de3cc699b54b02d7177418c8cf155afe929.tar.gz
kvision-0b349de3cc699b54b02d7177418c8cf155afe929.tar.bz2
kvision-0b349de3cc699b54b02d7177418c8cf155afe929.zip
Simplify state binding functions. Deprecate stateBinding() in favor of bind().
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/state')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt b/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt
index 20cb2d8e..d330f76d 100644
--- a/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt
@@ -5,6 +5,22 @@ package pl.treksoft.kvision.state
import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.core.Widget.Companion.bindState
+
+/**
+ * An extension function which binds the widget to the observable state.
+ *
+ * @param S the state type
+ * @param W the widget type
+ * @param observableState the state
+ * @param factory a function which re-creates the view based on the given state
+ */
+fun <S : Any, W : Widget> W.bind(
+ observableState: ObservableState<S>,
+ factory: (W.(S) -> Unit)
+): W {
+ return this.bindState(observableState, factory)
+}
/**
* A class which binds the given container to the observable state.
@@ -16,6 +32,7 @@ import pl.treksoft.kvision.core.Widget
* @param container the container
* @param factory a function which re-creates the view based on the given state
*/
+@Deprecated("Use bind function instead.")
class StateBinding<S : Any, CONT : Container, CONTENT>(
observableState: ObservableState<S>,
private val container: CONT,
@@ -64,6 +81,11 @@ class StateBinding<S : Any, CONT : Container, CONTENT>(
*
* It takes the same parameters as the constructor of the built component.
*/
+@Suppress("DEPRECATION")
+@Deprecated(
+ "Use bind function instead.",
+ replaceWith = ReplaceWith("bind(observableState, factory)", "pl.treksoft.kvision.state.bind")
+)
fun <S : Any, CONT : Container> CONT.stateBinding(
observableState: ObservableState<S>,
factory: (CONT.(S) -> Unit)
@@ -76,6 +98,8 @@ fun <S : Any, CONT : Container> CONT.stateBinding(
*
* It takes the same parameters as the constructor of the built component.
*/
+@Suppress("DEPRECATION")
+@Deprecated("Use bind function instead.")
fun <S : Any, CONT : Container, CONTENT> CONT.stateUpdate(
observableState: ObservableState<S>,
factory: (CONT.(S) -> CONTENT)
@@ -86,6 +110,7 @@ fun <S : Any, CONT : Container, CONTENT> CONT.stateUpdate(
/**
* A helper class for updateable content.
*/
+@Deprecated("Use bind function instead.")
class Updateable<S : Any, CONTENT>(private val setUpdateState: ((S, CONTENT) -> Unit) -> Unit) {
infix fun updateWith(updateState: (S, CONTENT) -> Unit) {
setUpdateState(updateState)