19
19
import javax .annotation .Nullable ;
20
20
21
21
import io .objectbox .annotation .apihint .Internal ;
22
+ import io .objectbox .query .Query ;
22
23
23
24
/**
24
25
* Builds a {@link DataSubscription} for a {@link DataObserver} passed via {@link #observer(DataObserver)}.
25
26
* Note that the call to {@link #observer(DataObserver)} is mandatory to create the subscription -
26
27
* if you forget it, nothing will happen.
27
28
* <p>
28
- * When subscribing to a data source such as {@link io.objectbox.query. Query}, this builder allows to configure:
29
+ * When subscribing to a data source such as {@link Query}, this builder allows to configure:
29
30
* <ul>
30
31
* <li>weakly referenced observer via {@link #weak()}</li>
31
32
* <li>a data transform operation via {@link #transform(DataTransformer)}</li>
@@ -78,11 +79,21 @@ public SubscriptionBuilder<T> weak() {
78
79
return this ;
79
80
}
80
81
82
+ /**
83
+ * Only deliver the latest data once, do not subscribe for data changes.
84
+ *
85
+ * @see #onlyChanges()
86
+ */
81
87
public SubscriptionBuilder <T > single () {
82
88
single = true ;
83
89
return this ;
84
90
}
85
91
92
+ /**
93
+ * Upon subscribing do not deliver the latest data, only once there are changes.
94
+ *
95
+ * @see #single()
96
+ */
86
97
public SubscriptionBuilder <T > onlyChanges () {
87
98
onlyChanges = true ;
88
99
return this ;
@@ -94,14 +105,12 @@ public SubscriptionBuilder<T> onlyChanges() {
94
105
// }
95
106
96
107
/**
97
- * Transforms the original data from the publisher to something that is more helpful to your application.
98
- * The transformation is done in an asynchronous thread.
99
- * The observer will be called in the same asynchronous thread unless a Scheduler is defined using
100
- * {@link #on(Scheduler)}.
108
+ * Transforms the original data from the publisher to some other type.
109
+ * All transformations run sequentially in an asynchronous thread owned by the publisher.
101
110
* <p>
102
- * This is roughly equivalent to the map operator as known in Rx and Kotlin.
111
+ * This is similar to the map operator of Rx and Kotlin.
103
112
*
104
- * @param <TO> The class the data is transformed to
113
+ * @param <TO> The type data is transformed to.
105
114
*/
106
115
public <TO > SubscriptionBuilder <TO > transform (final DataTransformer <T , TO > transformer ) {
107
116
if (this .transformer != null ) {
@@ -139,11 +148,16 @@ public SubscriptionBuilder<T> on(Scheduler scheduler) {
139
148
}
140
149
141
150
/**
142
- * The given observer is subscribed to the publisher. This method MUST be called to complete a subscription.
151
+ * Sets the observer for this subscription and requests the latest data to be delivered immediately
152
+ * and subscribes to the publisher for data updates, unless configured differently
153
+ * using {@link #single()} or {@link #onlyChanges()}.
154
+ * <p>
155
+ * Results are delivered on a background thread owned by the publisher,
156
+ * unless a scheduler was set using {@link #on(Scheduler)}.
143
157
* <p>
144
- * Note: you must keep the returned {@link DataSubscription} to cancel it .
158
+ * The returned {@link DataSubscription} must be canceled once the observer should no longer receive notifications .
145
159
*
146
- * @return an subscription object used for canceling further notifications to the observer
160
+ * @return A {@link DataSubscription} to cancel further notifications to the observer.
147
161
*/
148
162
public DataSubscription observer (DataObserver <T > observer ) {
149
163
WeakDataObserver <T > weakObserver = null ;
0 commit comments