in what situation should we use eventbus directly?

49 views
Skip to first unread message

wahaha

unread,
Dec 9, 2011, 4:43:27 AM12/9/11
to Google Web Toolkit
in what situation should we use eventbus directly?
if we do not need use it directly,then i think the design of the
structure of the map object in eventBus is too complex:
Map<Event.Type<?>, Map<Object, List<?>>>
actually,if we design it as Map<Event.Type<?>, List<?>>,then it can
satisfy the requirement of eventManger.because the "Object" key is
assigned with null in eventManager.
sorry for my poor english ..

Ed

unread,
Dec 9, 2011, 6:40:15 AM12/9/11
to Google Web Toolkit
You use the event bus directly when using triggering "own" events like
a Validation event or Show event when a part of the display needs to
be shown, etc..

wahaha

unread,
Dec 9, 2011, 7:16:27 AM12/9/11
to Google Web Toolkit
??
no,i just call fireEvent(event) in Wigdet to fire a customer defined
event.

Jens

unread,
Dec 9, 2011, 7:56:12 AM12/9/11
to google-we...@googlegroups.com
For example you could have a class that is responsible to show a message in your UI when it detects a long running task. Now this class needs the information when a tasks starts, when it stops and maybe it would also like to display a message depending on the task itself. 

As these tasks could be started everywhere in your app you would use the EventBus to transport these information to your class that should show the message if the task takes too long. So you would have a TaskStartEvent(String taskMessage), TaskFinishedEvent() and you would fire these events in presenters/controllers and not inside widgets. Thats an example where you use the EventBus directly with custom events outside of widgets.

And the map you have mentioned is not too complex. It has this structure because the EventBus supports handlers for specific event sources (which is the Object key in the map), see EventBus.fireFromSource() and EventBus.addHandlerToSource().

-- J.

wahaha

unread,
Dec 12, 2011, 1:57:54 AM12/12/11
to Google Web Toolkit
my english is very poor,but i try my best to understand your post.
i can not understand why don't you fire the events in widget,and why
the information that we need to compute if the time outside a range
must be transfered via eventbus?

Thomas Broyer

unread,
Dec 12, 2011, 4:46:16 AM12/12/11
to google-we...@googlegroups.com
In a few words: use EventBus to communicate between "big parts" of your app (e.g. between activities, if you use Places&Activities); you don't need an EventBus when dealing with widget events, simply use the widget's built-in mechanism: addHandler/addDomHandler, fireEvent. Use EventBus for higher-level (generally business-related) events: got there, done that, etc. e.g. "we'll be going to the User #123, U OK?" (PlaceChangeRequestEvent), "we've arrived at User #123" (PlaceChangeEvent), "Saving User #123" (custom event of your own), "User #123 has changed" (EntityProxyChange), "oops, looks like we've been signed out, session expired?" (custom event of your own).
Reply all
Reply to author
Forward
0 new messages