On Monday, March 4, 2013 10:31:21 AM UTC+1, Martones wrote:
Hey everyone,I noticed that my widget still listens to events from EventBus event after I remove them from the DOM and after I clear all my references to them. I was thinking if this was because of the EventBus bus handler the widget has. Or I am missing something !Anyway here is a simplified test illustrating this. The Event i'm using is a basic custom event and the Window.alert is there just to make sure the event is received.class TestWidget extends Composite {public TestWidget(final int id) {// register to eventEVENT_BUS.addHandler(UpdateDataEvent.TYPE, new UpdateDataEventHandler() {
From now on, the event bus has a reference on an UpdateDataEventHandler, which itself –being an anonymous, hence non-static, class– has a reference on the TestWidget, so the event bus has a reference on the widget.
When you want to "destroy" the widget, you then have to remove that handler.
It's generally a good idea to register/unregister from within the onLoad/onUnload methods of the widget, but if you want the widget to receive events even when not attached, then you have to provide an explicit "tear down" method so it unregisters all handlers from the event bus.
(btw: oh wow, a static event bus?)
-- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment