> 1- What is missing here is when would the Client UI typicallyAs with any event, I'd subscribe in the onLoad and unsubscribe in the
> subscribe/unsubscribe from the event bus. If this were a desktop
> application I would simply use weak reference so I would not have to
> unsubscribe my UI manually to prevent a memory leak.
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)
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?)
This I don't understand, onUnload is called by the parent widget
> Even if you make it a widget, having subscribed, since the
> eventbus has a reference to it, you won't get an unload.
(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.
Do you mean ornithologists?
Anyway, I think Thomas is talking about the presenter either being a
widget or wrapping a widget. Widgets are notified when their elements
are removed from the DOM, so you could conceivable make the presenter
aware of the DOM detachment and use that as a convenient time to "get
off the bus". As someone mentioned, though, if the widget is detached
from the DOM but still "alive" then it might get reattached at some
future time. If there was a real destructor then detached widgets
could continue to track state until destruction so they'd be up to
date when reattached. Of course, if wishes were horses....
Ian
On Thu, Jun 18, 2009 at 3:56 PM, Ian Bambury<ianba...@gmail.com> wrote:
> 2009/6/18 Thomas Broyer <t.br...@gmail.com>
>> Whether the eventbus has a reference to the widget isDo you mean ornithologists?
>> orthogonal.
>
> I didn't realise that widgets were bird-watchers! :-)
Anyway, I think Thomas is talking about the presenter either being a
widget or wrapping a widget. Widgets are notified when their elements
are removed from the DOM, so you could conceivable make the presenter
aware of the DOM detachment and use that as a convenient time to "get
off the bus".
Oh! You mean opthamologists! :D
>> Anyway, I think Thomas is talking about the presenter either being a
>> widget or wrapping a widget. Widgets are notified when their elements
>> are removed from the DOM, so you could conceivable make the presenter
>> aware of the DOM detachment and use that as a convenient time to "get
>> off the bus".
>
> My (limited) understanding of what Ray Ryan was saying (and what I
> understand of MVP) is that the presenter is completely separated from the
> DOM elements (in order to facilitate testing, and because the view is solely
> responsible for the view so you can swap views in and out as you please).
Your understanding of MVP is probably less limited than mine--I
assumed it was a riff on MVC. Anyway, couldn't you design an MVP
framework to include "I'm done paying attention to changes" events,
and use onUnload to trigger them when the presenter is using a widget
and use some other means when it's using something besides a widget?
Maybe we've drifted off into the weeds...
Ian
I have something like this:
public class Presenter {
...
private Display display;
interface Display {
HasClickHandlers getSaveButton();
HasClickHandlers getCancelButton();
HasClickHandlers getNumberField();
HasClickHandlers getLabelPicker();
}
void editPhone(Phone phone) {
this.phone = Phone.from(phone);
display.getNumberField().setValue(phone.getNumber());
display.getLabelPicker().setValue(phone.getLabel());
}
...
}
Obviously, a HasClickHandlers object doesn't have a setValue method.
It doesn't feel like I should be casting to the widget here, since we
went through all the trouble of using the Display interface.
I started looking at Mvp4g, but it seems to go off on a tangent with a
code generation class to wire up presenters and views via xml.
http://code.google.com/p/mvp4g/
It's also intertwined with some mvc4g classes.
I just want something basic that works, so I can seed my project from
there. A minimalist, working command style RPC example would be nice
too.
Anyone? If you're in the DC area, I'll buy you a drink!