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

Implement view attach events + tests #76

Closed
wants to merge 9 commits into from

Conversation

ZacSweers
Copy link
Contributor

As brought up in #70

@dlew and I talked in trello-archive/RxLifecycle#12 about it being nice if we could back its bindView implementation under the hood with the one you suggested in #70. This would also avoid the event class clashing if one uses both libraries.

public static final int DETACH = 1;

@IntDef({ATTACH, DETACH})
public @interface Kind {}
Copy link
Owner

Choose a reason for hiding this comment

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

All other events use an enum. If people want it changed that's a topic for a separate issue and should be done all at once. Switch this guy over.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, yeah I should've read the README. 0114616

* to free this reference.
*/
@CheckResult
public static Observable<ViewAttachEvent> attachEvents(View view) {
Copy link
Owner

Choose a reason for hiding this comment

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

Does this deserve a pair of siblings?

public static Observable<Object> attaches(View view) { .. }
public static Observable<Object> detaches(View view) { .. }

These are zero-allocation operators which appeals to me from an efficiency perspective, but I definitely struggle with the duplication they require on a code-size front (for those not using ProGuard, who I probably shouldn't care about and actually includes myself).

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 wondered about that, but wasn't sure if it was worth the trouble when filter exists. Maybe hold off for now keep the door open if anyone requests it?

Copy link
Owner

Choose a reason for hiding this comment

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

I mean, you can claim filter for every binding we have but then any action you take has to allocate a wrapper object and for particularly chatty events that cost will start to add up as your compose more and more bindings together. My struggle between these here is real.

Copy link
Owner

Choose a reason for hiding this comment

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

But I'm fine leaving it out here for now.

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 have an idea of how it could be done in a simple way, let me tinker for a min and get back to you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ehh idea didn't pan out (was thinking about generifying ViewAttachEventOnSubscribe).

Fair point on the wrapper allocations, though. Thinking of the RxLifecycle use case, it would actually be perfect for that, so I'll add those siblings. Should only be one extra *OnSubscribe class, so nothing too crazy with code duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done bb30a23

* *Warning:* The created observable keeps a strong reference to `view`. Unsubscribe
* to free this reference.
*/
public inline fun View.attaches(): Observable<Any> = RxView.attaches(this)
Copy link
Owner

Choose a reason for hiding this comment

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

I'm sad we can't make this Unit in Kotlin. Maybe we should write all the code in Kotlin and generate the Java bindings instead...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hindsight 🤔

@JakeWharton
Copy link
Owner

Squashed into two commits and merged. Thanks!

@JakeWharton JakeWharton closed this Aug 9, 2015
@ZacSweers ZacSweers deleted the z/view_attach_events branch August 9, 2015 05:13
@ZacSweers
Copy link
Contributor Author

Always happy to help! Looking forward to using this in the other PR and get back our view lifecycle binding 😀

@ZacSweers
Copy link
Contributor Author

Just noticed I forgot to add CheckResult annotations to the sibling methods... #82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants