You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-27Lines changed: 48 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Learn more about RxJava on the <ahref="https://github.com/ReactiveX/RxJava/wiki">Wiki Home</a> and the <ahref="http://techblog.netflix.com/2013/02/rxjava-netflix-api.html">Netflix TechBlog post</a> where RxJava was introduced.
4
4
5
-
RxJavaFX is a simple API to convert JavaFX events into RxJava Observables. It also has a scheduler to safely move emissions to the JavaFX Event Dispatch Thread.
5
+
RxJavaFX is a simple API to convert JavaFX events into RxJava Observables and vice versa. It also has a scheduler to safely move emissions to the JavaFX Event Dispatch Thread.
6
6
7
7
## Master Build Status
8
8
@@ -55,7 +55,7 @@ $ ./gradlew build
55
55
## Features
56
56
57
57
RxJavaFX has a lightweight set of features:
58
-
- Factories to turn `Node`, `ObservableValue`, and other component events into an RxJava `Observable`
58
+
- Factories to turn `Node`, `ObservableValue`, `ObservableList`, and other component events into an RxJava `Observable`
59
59
- Factories to turn an RxJava `Observable` into a JavaFX `Binding`.
The first factory`fromObservableList()` will simply emit the entire `ObservableList` every time there is `ListChange` event fired. The rest of the factories fire only items impacted by the `ListChange` events. The last three emit only *distinct* additions and removals, which can be helpful to emit only the first item with a given `hashcode()`/`equals()` and ignore dupe additions. When the last item (meaning no more dupes) is removed, only then will it fire the removal.
163
+
164
+
See the JavaDocsfor a more detailed description of each one.
165
+
140
166
###Binding
141
167
You can convert an RxJava `Observable` into a JavaFX `Binding` by calling the `JavaFxSubscriber.toBinding()` factory. Calling the `dispose()` method on the `Binding` will handle the unsubscription from the `Observable`.You can then take this `Binding` to bind other control properties to it.
142
168
@@ -146,9 +172,12 @@ Label incrementLabel = new Label("");
You also have the option to use a `CompositeBinding` to group multiple `Binding`s together, and `dispose()` them all at once. It is the JavaFX equivalent to `CompositeSubscription`.
190
+
191
+
```java
192
+
Binding<Long> binding1 =...
193
+
bindings.add(binding1);
194
+
195
+
Binding<Long> binding2 =...
196
+
bindings.add(binding2);
197
+
198
+
//do stuff on UI, and dispose() both bindings
199
+
bindings.dispose();
200
+
```
201
+
160
202
### JavaFXScheduler
161
203
162
204
When you update any JavaFX control, it must be done on the JavaFXEventDispatchThread. Fortunately, the `JavaFxScheduler` makes it trivial to take work off the JavaFX thread and put it back when the results are ready. Below we can use the `observeOn()` to pass text value emissions to a computation thread where the text will be flipped. Then we can pass `JavaFxScheduler.getInstance()` to another `observeOn()` afterwards to put it back on the JavaFX thread. From there it will update the `flippedTextLabel`.
@@ -181,29 +223,8 @@ Although ReactFX has some asynchronous operators like `threadBridge`, ReactFX em
181
223
182
224
If you are heavily dependent on RxJava, asynchronous processing, or do not want your entire reactive codebase to be UI-focused, you will probably want to use RxJavaFX.
183
225
184
-
185
-
186
226
##NotesforKotlin
187
-
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.
188
-
189
-
```kotlin
190
-
fun <T> Observable<T>.toBinding() =JavaFxSubscriber.toBinding(this)
191
-
fun <T> Observable<T>.toBinding(errorHandler: (Throwable) ->Unit) =JavaFxSubscriber.toBinding(this,errorHandler)
192
-
fun <T> ObservableValue<T>.toObservable() =JavaFxObservable.fromObservableValue(this)
193
-
fun <T> ObservableValue<T>.toObservableChanges() =JavaFxObservable.fromObservableValueChanges(this)
194
-
fun <T:Event> Node.toNodeEvents(eventType:EventType<T>) =JavaFxObservable.fromNodeEvents(this, eventType)
195
-
fun <T> Observable<T>.observeOnFx() =this.observeOn(JavaFxScheduler.getInstance())
196
-
```
197
-
This allows you to better use Kotlin's features to interop JavaFX and RxJava much more cleanly.
198
-
199
-
```kotlin
200
-
val textField =TextField()
201
-
val textInputs = textField.toObservable()
202
-
val lengthBinding = textInputs.map { it.length }.toBinding()
203
-
```
204
-
205
-
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.
206
-
227
+
If you are building your JavaFX application with [Kotlin](https://kotlinlang.org/), check out [RxKotlinFX](https://github.com/thomasnield/RxKotlinFX) to leverage this library through Kotlin extension functions.
0 commit comments