ground-android icon indicating copy to clipboard operation
ground-android copied to clipboard

[Code health] Simplify Rx streams by allowing subscribe() outside initialization

Open gino-m opened this issue 4 years ago • 0 comments

To ensure subscriptions did not accumulate until a view or view model is destroyed, we previously only allowed calls to subscribe() in initializers that would only be called once per lifecycle (e.g., onCreate(), constructors). For streams that need multiple subscriptions (e..g, on each click or other event) we would use switchMap, sometimes introducing a stream at top level to trigger a flow rather than subscribing directly on method invocation. This led to more complexity in the form of indirection.

In cases where the subscriptions are unlikely to accumulate (e.g., due to Single, Maybe, or Completable) we can subscribe inline. Subscriptions are cleaned up on termination anyway, and if we're concerned about leaking subscriptions, we can add timeouts or other strategies to dispose of the subscriptions.

Examples TBD.

gino-m avatar Nov 24 '21 15:11 gino-m