orangy
fun <T, R> ObservableValue<T>.debounce(duration: Duration, evaluate: (T?) -> R?): ObservableValue<R> {
val pause = PauseTransition(duration)
val property = SimpleObjectProperty<R>()
property.set(evaluate(value))
onChange { inputValue ->
pause.setOnFinished { property.set(evaluate(inputValue)) }
pause.playFromStart()
}
return property
}
Ruckus
06/26/2018, 4:28 PMsetOnFinished
call out of the onChange
call so you're not changing the property every time. Something like
pause.setOnFinished { property.set(evaluate(value)) }
onChange { pause.playFromStart() }
orangy
inputValue
? Not sure I understandabhinay
06/26/2018, 5:53 PMgetValue()
(in Kotlin value
).Ruckus
06/26/2018, 6:02 PMorangy
evaluate
in a background thread eventually 😉Ruckus
06/26/2018, 6:17 PM