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

Feature: subscriber registration with downcasting event type. #101

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

yaitskov
Copy link

Hi,

I've built an event barrier library with EventBus to trigger an action by a composite event.
For example turn on location service if battery ok, online and oauth session is valid. This approach uses
heavily a composite pattern (GoF).

Now I have to write a lot of stub classes to declare onEvent with required argument type.
With ability to point obviously event type of subscriber this can be done in runtime.
Logic of all my event handlers is the same. So in this case it is redundant to declare one method per event.
It's more convenient just to list base atomic event classes as arguments of a builder method.

@yaitskov yaitskov changed the title Feature: subscriber registeration with downcasting event type. Feature: subscriber registration with downcasting event type. Jun 15, 2014
@greenrobot
Copy link
Owner

I don't get what's the use case here. You are aware that EventBus already considers event type hierarchy? E.g. onEvent(Object) catches all events?

@yaitskov
Copy link
Author

yaitskov commented Nov 8, 2014

Yeah onEvent(Object) catches all events, but I want to receive just classes A and B for such method signature.
Now I don't see how to do this without implementing event handler class for each event type.
These handles are lazy classes because they do nothing more than telling an accepting event class.

@yaitskov
Copy link
Author

yaitskov commented Nov 8, 2014

Here is my use case https://github.com/yaitskov/event-barrier/blob/master/src/test/java/com/github/ebar/EventBarrierTest.java.
Look at method allOfBarrier.

You know an Android app should be adaptive. The test shows how to keep an application active only if battery has power, device is online, and application has valid user session token.

The test is very clumsy because of helping boilerplate classes.

@greenrobot
Copy link
Owner

I still don't get what you are doing with barriers and events. I'm not sure if that would be something lots of people would like to use.

If case you want to do something similar to register(Object subscriber, Class eventType, Class... moreEventTypes) --> note the "@deprecated For simplification of the API, this method will be removed in the future."

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.

2 participants