airbnb / RxGroups

Easily group RxJava Observables together and tie them to your Android Activity lifecycle
Apache License 2.0
693 stars 44 forks source link

Add AutoTag, NonResubscribableTag, safeInitialize #41

Closed BenSchwab closed 7 years ago

BenSchwab commented 7 years ago

While integrating 1.0 in real use case, I found that the following changes were very useful:

First, based on our use case, RxGroups is useful to manage observables even if you never intend to resubscribe. This is because RxGroup offers the ability to:

In our real use, we did in fact use RxGroups with observables that we had no intent to resubscribe to. This PR moves some logic into RxGroups to make this use case more explicit. Noticeably, RxGroups accepts plain observers for most methods now. If the observable does not implement TaggedObserver then we use a identifiable variant of hashcode. However, with plain Observer's resubscribing does not make sense, thus resubscribe will remain TaggedObserver. To cut down on memory leaks, we can clear out "NonResubscribable" Observers on a non-finishing destroy.

Another use case we need is the ability to separate AutoResubscribing from AutoTagging. We have a handful of cases were we want to have a auto generated tag, but we cannot resubscribe the observable onCreate. This PR allows this cases to be solved by using the AutoTag annotation, which will set the unique tag on the observer, but will require the user to explicitly call Resubscribe.

~Finally, this adds a 'safeInitialize' method for group creation, and uses it for onCreate. I see the value in a "Butterknife throw if class not generated style code" but this causes problems for architectures that rely on call init in a base class and where the derived class may have no AutoResubscribe listeners, and thus no generated code (our arch). Currently leaving the old method in, but wonder if we should just standardize on no error for simplicity.~

Todo:

BenSchwab commented 7 years ago

want to call out https://github.com/airbnb/RxGroups/pull/41/commits/e71be8075463d1d3f7f689b6a1dc9fc278805aaa as it adds support for binding super classes