Global Event bus for separate compilation modules

139 views
Skip to first unread message

Ahmad Bawaneh

unread,
Apr 24, 2016, 1:08:29 PM4/24/16
to GWT Users
Dears,
is there any way to build an event bus that can fire events and these events to be handled by handler in another module that is compiled separately and included inside the html as a script.

Thanks

Luigi Bifulco

unread,
Apr 27, 2016, 1:09:20 AM4/27/16
to GWT Users
What do you mean for separate modules? Gwt enables to develop separate modules but during compilation time you will get a unique javascript source... if you mean that you have more than one entry point I can imagine that you are running them in separate window or separate iframe. If so you can build an event driven interface trough Window.postMessage, when a window receives a message you can intercept it with window.addEventListener('message', listener). More info on https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

Thomas Broyer

unread,
Apr 27, 2016, 3:47:38 AM4/27/16
to GWT Users
No, I think Ahmad is talking about the "turducken" architecture. I just stumbled on http://gwtdaily.com/post/79849550460/gwt-interappeventbus which should answer the question (with link to the presentation about the original concept)

Pavlo Iatsiuk

unread,
Apr 27, 2016, 8:58:20 AM4/27/16
to GWT Users
I have just suggestion to use some JS eventbus, expose it as global JS object and get reference on that in both modules.

Luigi Bifulco

unread,
Apr 27, 2016, 1:29:45 PM4/27/16
to GWT Users
I understand the turducken model that but I not suggest the linked implementation because the gwt compiler in that way will produce redundant code in each module and this can cause some problems at runtime of js code. I suggest to use a global js object and reference it trough a native jsni method. Using window.post is a specific way to reuse a global JS object and obtain a messaging mechanism with a single call and without the problems I see in re-writing the bus as a gwt module. With gwt 2.8 this problem is solved with jsinterop.
Reply all
Reply to author
Forward
0 new messages