An EventBus with less boiler plate

64 views
Skip to first unread message

George Georgovassilis

unread,
May 19, 2019, 4:02:09 PM5/19/19
to GWT Users
Apologies if this has been discussed before. The EventBus requires the declaration of an Event class and a Handler interface for each activity of interest, which often results in plenty of boiler plate. In one of our projects we came up with a simpler notation which doesn't require event classes - so all we write are Handler interfaces (and their implementations). This does however require a modified event bus.

Firing an event can be as simple as:

bus.fireEvent(Types.transactionEvents, (l)->l.deposit(depositDate, 150, "ATM"));

The traditonal event/handler design template always implements these steps:

- sender package data into an event
- sender fires event on the event bus
- event bus locates handlers and executes event on them
- event invokes a method on the handler and passes packaged data as arguments

The idea here is that it is slightly less work to directly invoke a listener method with the appropriate arguments instead of going through the event pack/unpack procedure.

The repo is here: https://github.com/ggeorgovassilis/lambda-listeners, feel free to use any way you like.
Reply all
Reply to author
Forward
0 new messages