Skip to content

Commit f779056

Browse files
committed
Merge branch '0.x' of https://github.com/ReactiveX/RxJavaFX into 0.x
2 parents ac5f803 + b0076f7 commit f779056

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

README.md

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -137,31 +137,29 @@ Subscription subscription = JavaFxObservable.fromObservableValueChanges(spinner.
137137
.subscribe(spinnerChangesLabel::setText);
138138
```
139139

140-
###ObservableList
140+
###ObservableList, ObservableMap, and ObservableSet
141+
142+
There are several factories to emit many useful `ObservableList`, `ObservableMap`, and `ObservableSet` events as Observables. These all can be found as static factory methods in the `JavaFxObservable` static class.
143+
144+
145+
|Factory Method|Parameter Type|Return Type|Description|
146+
|---|---|---|---
147+
|fromObservableList()|ObservableList<T>|Observable<ObservableList<T>>|Emits the entire `ObservableList` every time it changes|
148+
|fromObservableListAdds()|ObservableList<T>|Observable<T>|Emits additions to an `ObservableList`|
149+
|fromfromObservableListRemovals()|ObservableList<T>|Observable<T>|Emits removals from an `ObservableList`|
150+
|fromObservableListUpdates|ObservableList<T>|Observable<ListChange<T>>|Emits every item that was the result of a change to an `ObservableList`, with an `ADDED`, `REMOVED`, or `UPDATED` flag|
151+
|fromObservableListDistinctChanges()|ObservableList<T>| Observable<ListChange<R>>|Emits only *distinct* addtions and removals to an `ObservableList`|
152+
|fromObservableListDistinctChanges()|ObservableList<T>, Func1<T,R>| Observable<ListChange<R>>|Emits only *distinct* additions and removals to an `ObservableList` and emits the mapping|
153+
|fromObservableListDistinctChanges()|ObservableList<T>, Func1<T,R>| Observable<ListChange<R>>|Emits only *distinct* additions and removals to an `ObservableList` based on a mapping|
154+
|fromObservableMap()|ObservableMap<K,T>|Observable<ObservableMap<K,T>>|Emits the entire `ObservableMap` every time it changes|
155+
|fromObservableMapAdds()|ObservableMap&lt;K,T>|Observable&lt;Map.Entry&lt;K,T>>|Emits every `Map.Entry<K,T>` added to an `ObservableMap`|
156+
|fromObservableMapRemovals()|ObservableMap&lt;K,T>|Observable&lt;Map.Entry&lt;K,T>>|Emits every `Map.Entry<K,T>` removed from an `ObservableMap`|
157+
|fromObservableMapChanges()|ObservableMap&lt;K,T>|Observable&lt;MapChange&lt;K,T>>|Emits every key/value pair with an `ADDED` or `REMOVED` flag.|
158+
|fromObservableSet()|ObservableSet&lt;T>|Observable&lt;ObservableSet&lt;T>>|Emits the entire `ObservableSet` every time it changes|
159+
|fromObservableSetAdds()|ObservableSet&lt;T>|Observable&lt;T>|Emits every addition to an `ObservableSet`|
160+
|fromObservableSetRemovals()|ObservableSet&lt;T>|Observable&lt;T>|Emits every removal to an `ObservableSet`|
161+
|fromObservableSetChanges()|ObservableSet&lt;T>|Observable&lt;SetChange&lt;T>|Emits every item `ADDED` or `REMOVED` item from an `ObservableSet` with the corresponding flag|
141162

142-
There are eight factories in `JavaFxObservable` for turning an `ObservableList` into an `Observable` of some form based on a `ListChange` event.
143-
144-
```java
145-
public static <T> Observable<ObservableList<T>> fromObservableList(final ObservableList<T> source
146-
147-
public static <T> Observable<T> fromObservableListAdds(final ObservableList<T> source)
148-
149-
public static <T> Observable<T> fromObservableListRemovals(final ObservableList<T> source)
150-
151-
public static <T> Observable<T> fromObservableListUpdates(final ObservableList<T> source)
152-
153-
public static <T> Observable<ListChange<T>> fromObservableListChanges(final ObservableList<T> source)
154-
155-
public static <T> Observable<ListChange<T>> fromObservableListDistinctChanges(final ObservableList<T> source)
156-
157-
public static <T,R> Observable<ListChange<T>> fromObservableListDistinctChanges(final ObservableList<T> source, Func1<T,R> mapper)
158-
159-
public static <T,R> Observable<ListChange<R>> fromObservableListDistinctMappings(final ObservableList<T> source, Func1<T,R> mapper)
160-
```
161-
162-
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 JavaDocs for a more detailed description of each one.
165163

166164
###Binding
167165
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.

src/main/java/rx/javafx/sources/ObservableMapSource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static <K,T> Observable<Entry<K,T>> fromObservableMapAdds(final Observabl
2828
MapChangeListener<K,T> listener = c -> {
2929

3030
if (c.wasAdded()) {
31-
subscriber.onNext(new SimpleEntry<>(c.getKey(),c.getValueAdded()));
31+
subscriber.onNext(new SimpleEntry<K,T>(c.getKey(),c.getValueAdded()));
3232
}
3333

3434
};
@@ -45,7 +45,7 @@ public static <K,T> Observable<Entry<K,T>> fromObservableMapRemovals(final Obser
4545
MapChangeListener<K,T> listener = c -> {
4646

4747
if (c.wasRemoved()) {
48-
subscriber.onNext(new SimpleEntry<>(c.getKey(),c.getValueRemoved()));
48+
subscriber.onNext(new SimpleEntry<K,T>(c.getKey(),c.getValueRemoved()));
4949
}
5050

5151
};
@@ -62,10 +62,10 @@ public static <K,T> Observable<MapChange<K,T>> fromObservableMapChanges(final Ob
6262
MapChangeListener<K,T> listener = c -> {
6363

6464
if (c.wasRemoved()) {
65-
subscriber.onNext(new MapChange<>(c.getKey(),c.getValueRemoved(),Flag.REMOVED));
65+
subscriber.onNext(new MapChange<K,T>(c.getKey(),c.getValueRemoved(),Flag.REMOVED));
6666
}
6767
if (c.wasAdded()) {
68-
subscriber.onNext(new MapChange<>(c.getKey(),c.getValueAdded(),Flag.ADDED));
68+
subscriber.onNext(new MapChange<K,T>(c.getKey(),c.getValueAdded(),Flag.ADDED));
6969
}
7070

7171
};

src/main/java/rx/javafx/sources/ObservableSetSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public static <T> Observable<SetChange<T>> fromObservableSetChanges(final Observ
5454

5555
SetChangeListener<T> listener = c -> {
5656
if (c.wasRemoved()) {
57-
subscriber.onNext(new SetChange<>(c.getElementRemoved(), Flag.REMOVED));
57+
subscriber.onNext(new SetChange<T>(c.getElementRemoved(), Flag.REMOVED));
5858
}
5959
if (c.wasAdded()) {
60-
subscriber.onNext(new SetChange<>(c.getElementAdded(), Flag.ADDED));
60+
subscriber.onNext(new SetChange<T>(c.getElementAdded(), Flag.ADDED));
6161
}
6262
};
6363
source.addListener(listener);

0 commit comments

Comments
 (0)