Reputation: 85
I am creating an MVP-like application in GWT.
To put my concern more precisely: why introduce an Event Bus at all, rather than simply letting events "bubble up" to the appropriate decision-making level? To me this seems like the most straightforward extension of the MVP concept, and it doesn't require the new idea of an Event Bus. I don't understand what problem the Event Bus was introduced to solve.
Upvotes: 6
Views: 427
Reputation: 16060
The advantage of the eventbus is separation of the code.
You can just fire custom events to the bus and don't need to care about your event anymore. Every presenter subscribes only to that events, which it really needs to know. This will lead into cleaner code because, you don't have to create a dispatcher which has to know all presenter to delegate events to them.
In my opinion, the eventbus is a really good thing, to make the code clean and easily understandable.
Upvotes: 8
Reputation: 64541
Your proposed approach is fine, with one big drawback: it calls for spaghetti code when your app grows.
This presentation is about Android but the arguments hold for GWT too.
See also this famous presentation from Google I/O 2009 which explicitly talks about Use an Event Bus to fight spaghetti code (a must-watch if you haven't already).
Finally, this blog post deals with the observer vs. mediator patterns in JS: in GWT, the observer pattern is realized by event handlers whereas the mediator pattern is realized by the event bus. Here's the tl;dr: « use observer “locally”, inside a component, mediator “remotely” between components. »
Upvotes: 3