Skip to content

Commit edfbbbd

Browse files
committed
Update README.md
1 parent fe0033e commit edfbbbd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,26 @@ sub2 = textInputs.observeOn(Schedulers.computation())
132132
.observeOn(JavaFxScheduler.getInstance())
133133
.subscribe(fippedTextLabel::setText);
134134
```
135+
##Notes for Kotlin
136+
If you are building your JavaFX application with [Kotlin](https://kotlinlang.org/), this library becomes even more useful with extension functions. These extension functions exist in the [RxKotlinFX](https://github.com/thomasnield/RxKotlinFX) project, but the API is so small it is not worth publishing at the moment. But you can simply add these extension functions below to your project and utilize Kotlin's fluent style.
137+
138+
```kotlin
139+
fun <T> Observable<T>.toBinding() = JavaFxSubscriber.toBinding(this)
140+
fun <T> Observable<T>.toBinding(errorHandler: (Throwable) -> Unit) = JavaFxSubscriber.toBinding(this,errorHandler)
141+
fun <T> ObservableValue<T>.toObservable() = JavaFxObservable.fromObservableValue(this)
142+
fun <T> ObservableValue<T>.toObservableChanges() = JavaFxObservable.fromObservableValueChanges(this)
143+
fun <T> Observable<T>.toFxScheduler() = observeOn(JavaFxScheduler.getInstance())
144+
fun <T : Event> Node.toNodeEvents(eventType: EventType<T>) = JavaFxObservable.fromNodeEvents(this, eventType)
145+
fun <T> Observable<T>.observeOnFx() = this.observeOn(JavaFxScheduler.getInstance())
146+
```
147+
This allows you to better use Kotlin's features to interop JavaFX and RxJava much more cleanly.
148+
149+
```kotlin
150+
val sourceObservable = Observable.just("Alpha","Beta","Gamma")
151+
val lengthBinding = sourceObservable.map { it.length }.toBinding()
152+
```
153+
154+
If you are doing JavaFX and Kotlin development, definitely check out [TornadoFX](https://github.com/edvin/tornadofx) as well to utilize type-safe builders and other features enabled by Kotlin.
135155

136156
##Differences from ReactFX
137157
[ReactFX](https://github.com/TomasMikula/ReactFX) is a popular API to implement reactive patterns with JavaFX using the `EventStream`. However, RxJava uses an `Observable` and the two are not (directly) compatible with each other.

0 commit comments

Comments
 (0)