https://kotlinlang.org logo
j

jschneider

02/15/2021, 8:13 PM
I have created this extension method:
Copy code
/**
 * Adds the css class if the given predicate returns true.
 */
fun <T> Component.addCssClassIf(observableValue: ObservableValue<T>, cssClass: String, predicate: (T) -> Boolean) {
  observableValue.subscribe {
    if (predicate(it)) {
      addCssClass(cssClass)
    } else {
      removeCssClass(cssClass)
    }
  }
}
I have the feeling that this should be possible with kvision stuff, correct?