Sunday, May 19, 2019

An EventBus with less boiler plate

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.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/dac1af20-2eab-47c2-9e6b-a85b95c880e6%40googlegroups.com.

No comments:

Post a Comment