2009/6/18 Thomas Broyer <t.bro...@gmail.com> > > > > On 18 juin, 18:01, Ian Bambury < ianbamb...@gmail.com> wrote: > > 2009/6/12 Thomas Broyer <t.bro...@gmail.com> > > > > > As with any event, I'd subscribe in the onLoad and unsubscribe in the > > > onUnload (would be even better if there was a destructor, so that even > > > when not attached to the DOM, your widget could receive events and > > > enter a "dirty" state, so that when it is attached again to the DOM it > > > knows if it has to refresh or not) > > > > I didn't understand that bit. > > > > The presenter needs to subscribe but is just a class and doesn't have an > > onUnload method. > > Right! > (couldn't we make the presenters all have onLoad/onUnload methods to > be called by other components when they make use of a presenter; in > the Google I/O slides, the presenter as a method go(Widget) which is > almost equivalent to Widget::onLoad, what happens when you don't need > the component any more, it must have some other method that would be > similar to Widget::onUnload, no? of course, it would mean that > developers have to make sure they call that onUnload method when they > no longer need a component; some asserts in a window.onunload could > make it easier to discover those leaks: the eventbus shouldn't have > any subscriber left. Did I say I'm not really used to MVC/MVP?) >
That was my point, really, that there is no method you can just shove the unsubscribe into and have it just happen. You have to create one (calling it what you will, unload(), teardown(), destroy(), etc) and hope the developers will remember to call it. > > > Even if you make it a widget, having subscribed, since the > > eventbus has a reference to it, you won't get an unload. > > This I don't understand, onUnload is called by the parent widget > (through onDetach) when you remove its child (and it thus is detached > from the DOM). Whether the eventbus has a reference to the widget is > orthogonal. > I didn't realise that widgets were bird-watchers! :-) Maybe an example would help explain the problem (either the problem in general, or my problem). There's an eventbus which is just a singleton for a HandlerManager with some methods for it for requesting data and for registering handlers. The requests might be batched and/or the data might be cached or retrieved from the server, it doesn't matter. If getTemperature() is called, some time later the data will arrive and all the TemperatureUpdateHandlers will get the onTemperatureUpdate(TemperatureUpdateEvent event) methods called. Anything anywhere requests a current temperature, then everything interested gets told when the news arrives. The TemperatureAsTextView class extends Composite and is just a label with the temperature in text The TemperatureAsText class is the presenter. It extends nothing. To use all this, you need to create a TemperatureAsTextView object, passing it the panel it is to add itself to. TemperatureAsTextView view = new TemperatureAsTextView (panel); The view adds itself to the panel. In some way or another, the view is bound to an instance of the presenter. The view might create the presenter for example. Let's stick with that. So we have a view on a panel being controlled by a presenter. And we have a bus which lets us register TemperatureUpdateHandlers and also request the temperature. The presenter registers itself with the bus. This is my problem, I can't see a way to automatically unregister the presenter. You have to hope the programmer remembers to do it (via whatever name you chose - unload/destroy/zap...) You can't easily make it safe. You can't register the view or any part of it because the whole idea is that the logic is in the presenter, and you can't have the presenter be part of the view because that is against the principles of MVP So you have to hope the programmer knows to and remembers to call the method to remove the handlers. And that is not ideal in my book. Ian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---