It's terrible to define lots of Custom events when post and subcribe
See original GitHub issueI am Confused whether make use of eventbus to reconstruction my code, cause eventbus must define lots of Custom events,each action should have relevant event.
I think it’s terrible。
what i am think is changing post(object event), post(Event event), most of time ,I just post a Event, an it’s filterSet act as a FILTER that who can accept this Event。
that means the Event know that I will not serve others,I just serve filterSet declared.
filterSet may be { “com.test.demoActivity.class”,“com.test.demoActivity2.class”}
SO, my question is :What Problems of this design
public class Event{ public Set<String> filterSet; public Object msg; }
private void postToSubscription(Subscription subscription, Event event, boolean isMainThread) {
//add filter condition
if(!event.filter.isEmpty() && !event.filter.contains(subscription.subscriber.getClass())){
return ;
}
switch (subscription.subscriberMethod.threadMode) {
case PostThread:
invokeSubscriber(subscription, event);
break;
case MainThread:
if (isMainThread) {
invokeSubscriber(subscription, event);
} else {
mainThreadPoster.enqueue(subscription, event);
}
break;
case BackgroundThread:
if (isMainThread) {
backgroundPoster.enqueue(subscription, event);
} else {
invokeSubscriber(subscription, event);
}
break;
case Async:
asyncPoster.enqueue(subscription, event);
break;
default:
throw new IllegalStateException("Unknown thread mode: " + subscription.subscriberMethod.threadMode);
}
}
Issue Analytics
- State:
- Created 9 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Dispatching custom events - The Modern JavaScript Tutorial
Custom events can be used to create “graphical components”. ... assign any properties into a regular new Event object after its creation.
Read more >Is it poor form for a C# class to subscribe to its own published ...
After saying the above, normally there is no great harm in subscribing to your own event; in UI classes that represent forms it...
Read more >Using custom events in React - LogRocket Blog
Learn how to build your own custom events in React apps, an essential skill for frontend devs of all levels, in this complete...
Read more >Social Media Event Promotion: The Complete Guide
6 ways to promote an event on social media before it happens · 1. Post a countdown on Instagram Stories · 2. Create...
Read more >Should You Put Several Event Types in the Same Kafka Topic?
In this context, I believe it's less important to define a topic as a grouping of messages with the same schema. Much more...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh ouch, posts msdn reference…
IMHO what I was most worried about with an enum/type/filter pattern (I also tried it) was that too many registered listeners would fire and interrupt things unnecessarily. Until they each figured out that the message was not for them. Hence the anit-pattern.
The routing tools you have with EventBus are:
Not sure if best practice but this is what I have found myself doing:
@gavingc
yes ,I have thought about it. creating several buses according to logic module, but you should register several subscriber in one component(Activity),and it will make you puzzled when post Events, you must choose the right bus to send a post ,especially when someThing across Componnet ,across modules
and i have not understand what’s problem does your example code fixed