Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for exposing delegate observers. #89

Merged
merged 13 commits into from
Sep 22, 2017

Conversation

mswysocki
Copy link
Contributor

Resolves #78

This change updated AutoDisposingSubscriber implement FlowableSubscriber instead of Subscriber. We wanted to have more consistency with how the rest of the Observers are handled in RxJava. This change remains backward compatible because FlowableSubscriber still extends Subscriber.

This also exposes all the different implementations of Observer to allow for introspection to the delegate Observer. This will be particularly useful for ReactiveX/RxJava#5590.

@mswysocki mswysocki added this to the 0.3.0 milestone Sep 21, 2017
@mswysocki mswysocki self-assigned this Sep 21, 2017
@CLAassistant
Copy link

CLAassistant commented Sep 21, 2017

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@ZacSweers ZacSweers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! From a high level I think there's a few changes we should make that are across the observers:

  • Let's inline the {@link Observer} mentions in docs, it should read like a sentence since they are linkified inline. Make sure you link the correct observer as well (e.g. right now they all use Observer but there is a unique Observer for each type, like SingleObserver).
  • Let's add a comment to the docs that explicitly call out that this API will change once the LambdaIntrospection stuff is out of @Experimental in RxJava (at which point we'll update it to return that interface instead and mark it nullable to return null upon non conforming types).
  • Let's add @Experimental to all the methods to indicate their plans to change. Borrow the RxJava annotation.
  • Let's make the atomic references in tests local to their specific unit tests rather than fields since they're only used in those methods.
  • Use reference comparison for the delegate observer in tests, not isEqualTo (which checks equality and isn't what we want).

@@ -24,4 +25,4 @@
* A {@link Disposable} {@link Subscriber} that can automatically dispose itself. Interface here
* for type safety but enforcement is left to the implementation.
*/
public interface AutoDisposingSubscriber<T> extends Subscriber<T>, Subscription, Disposable {}
public interface AutoDisposingSubscriber<T> extends FlowableSubscriber<T>, Subscription, Disposable {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: would be good to include a tidbit of the explanation you put in the PR description in this commit message

public interface AutoDisposingObserver<T> extends Observer<T>, Disposable {

/**
* @return {@link Observer} The delegate Observer that is used under the hood for introspection purposes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Did you mean to link the Observer here rather than inline?

I'd expect this to be like @return The delegate {@link Observer} that is used under the hood for introspection purposes.

assertThat(atomicAutoDisposingObserver.get()).isInstanceOf(AutoDisposingObserver.class);
assertThat(((AutoDisposingObserver)atomicAutoDisposingObserver.get()).delegateObserver()).isNotNull();
assertThat(((AutoDisposingObserver)atomicAutoDisposingObserver.get()).delegateObserver())
.isEqualTo(atomicObserver.get());
Copy link
Collaborator

@ZacSweers ZacSweers Sep 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a reference check, not equality

import org.junit.After;
import org.junit.Test;

import static com.google.common.truth.Truth.assertThat;

public class AutoDisposeObserverTest {

private final AtomicReference<Observer> atomicObserver = new AtomicReference();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since these are only used in one test, let's make them final local variables in those methods instead

@@ -154,7 +162,7 @@
lifecycle.onNext(1);
source.onNext(2);

assertThat(source.hasObservers()).isTrue();
assertThat(source.hasObservers()).isTrue();Å
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wat.gif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was from you trying to use my keyboard.

@mswysocki
Copy link
Contributor Author

mswysocki commented Sep 22, 2017

Let's inline the {@link Observer} mentions in docs, it should read like a sentence since they are linkified inline. Make sure you link the correct observer as well (e.g. right now they all use Observer but there is a unique Observer for each type, like SingleObserver).

e3dd21a

Let's add a comment to the docs that explicitly call out that this API will change once the LambdaIntrospection stuff is out of @experimental in RxJava (at which point we'll update it to return that interface instead and mark it nullable to return null upon non conforming types).

bda1040

Let's add @experimental to all the methods to indicate their plans to change. Borrow the RxJava annotation.

bda1040

Let's make the atomic references in tests local to their specific unit tests rather than fields since they're only used in those methods.

7270758

Use reference comparison for the delegate observer in tests, not isEqualTo (which checks equality and isn't what we want).

45e6c31

Copy link
Collaborator

@ZacSweers ZacSweers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woo!

@ZacSweers ZacSweers merged commit 5af3987 into uber:master Sep 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants