Class SubscriptionBuilder<T>
- Type Parameters:
T
- The data type theDataObserver
subscribes to.
DataSubscription
for a DataObserver
passed via observer(DataObserver)
.
Note that the call to observer(DataObserver)
is mandatory to create the subscription -
if you forget it, nothing will happen.
When subscribing to a data source such as Query
, this builder allows to configure:
- weakly referenced observer via
weak()
- a data transform operation via
transform(DataTransformer)
- error handlers via
onError(ErrorObserver)
- calling the observer using a custom
Scheduler
(e.g. Android main thread) viaon(Scheduler)
Note: the order of methods called in this do not matter. Unlike Rx's Observeable, this builder just collects all info. For example, on(scheduler).transform(transformer) is the same as transform(transformer).on(scheduler).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondataSubscriptionList
(DataSubscriptionList dataSubscriptionList) observer
(DataObserver<T> observer) Sets the observer for this subscription and requests the latest data to be delivered immediately.Changes the thread in which theDataObserver
(and potentially @ErrorObserver
) is called.onError
(ErrorObserver errorObserver) The givenErrorObserver
is notified when theDataTransformer
(transform(DataTransformer)
) orDataObserver
(observer(DataObserver)
) threw an exception.Upon subscribing do not deliver the latest data, only once there are changes.single()
Only deliver the latest data once, do not subscribe for data changes.<TO> SubscriptionBuilder<TO>
transform
(DataTransformer<T, TO> transformer) Transforms the original data from the publisher to some other type.weak()
Uses a weak reference for the observer.
-
Constructor Details
-
SubscriptionBuilder
-
-
Method Details
-
weak
Uses a weak reference for the observer. It is still advised to remove observers explicitly if possible: relying on the garbage collection may cause non-deterministic timing. Until the weak reference is actually cleared by GC, it may still receive notifications. -
single
Only deliver the latest data once, do not subscribe for data changes.- See Also:
-
onlyChanges
Upon subscribing do not deliver the latest data, only once there are changes.- See Also:
-
transform
Transforms the original data from the publisher to some other type. All transformations run sequentially in an asynchronous thread owned by the publisher.This is similar to the map operator of Rx and Kotlin.
- Type Parameters:
TO
- The type data is transformed to.
-
onError
The givenErrorObserver
is notified when theDataTransformer
(transform(DataTransformer)
) orDataObserver
(observer(DataObserver)
) threw an exception. -
on
Changes the thread in which theDataObserver
(and potentially @ErrorObserver
) is called.In the Android package, there is a class AndroidScheduler with a MAIN_THREAD Scheduler implementation. Using MAIN_THREAD, observers will be called in Android's main thread, which is required for UI updates.
-
observer
Sets the observer for this subscription and requests the latest data to be delivered immediately. Subscribes to receive data updates. This can be changed by usingsingle()
oronlyChanges()
.Results are delivered on a background thread owned by the internal data publisher, unless a scheduler was set using
on(Scheduler)
.The returned
DataSubscription
must be canceled once the observer should no longer receive data. -
dataSubscriptionList
-