Hi Jens,
Thanks for replying back with an example. You answered what I am needing 
for. So that definitely helps. I kind of thought about this approach but 
couple of things I found here which I am not sure is better way to do that.

1) My presenter would need additional dependencies like ClientFactory, 
EventBus. That means my MyCustomWidget need to have ClientFactory, EventBus 
so that I can pass them to the Presenter. Considering we want to make our 
MVP Views as dumb as possible and have only GWT widget code inside is this 
okay to include ClientFactory, EventBus in your View class now?

2) If you see the classic GWT MVP view, Place instantiates an Activity 
class passing ClientFactory in it's constructor and Activity class start 
method uses ClientFactory to get the view and assign itself inside the view 
as it's presenter. Whereas your way is opposite where your Composite View 
class is instantiating Activity through it's constructor and passing itself 
to the Presenter. 

3) If I am referencing this Custom Composite View MyCustomWidget in another 
Ui Binder View how do I pass ClientFactory, EventBus to this MyCustomWidget 
using UIBinder? That means I have to pass ClientFactory, EventBus to every 
Parent View so that it can get passed to the  MyCustomWidget if that view 
is using it. This kind of differs to existing Activities & Places framework 
where MVP View doesn't hold ClientFactory, EventBus objects but it's 
Activity class do.

What do you think?



On Wednesday, September 12, 2012 10:40:11 AM UTC-5, Jens wrote:
>
> The fact that a custom widget uses MVP should be hidden so you would end 
> up having:
>
> MyCustomWidget extends Composite implements CustomView {
>
>   MyCustomWidget() {
>     myPresenter = new Presenter(this); //takes CustomView as argument so 
> you can mock the view while testing the presenter
>   }  
>
>    public void myCoolMethod() {
>       myPresenter.doTheTestableWorkForMe(); //delegation to presenter if 
> wanted/needed
>    }
>
> }
>
> If your presenter needs additional dependencies you would pass through 
> your ClientFactory, e.g.
>
> MyCustomWidget(ClientFactory factory) {
>   myPresenter = new Presenter(this, factory);
> }
>
> The presenter would be package private so no one outside the package can 
> use it but you can still test the presenter as the test typically resides 
> in the same package.
>
> I think this works best for complex widgets and it is the same strategy as 
> the cell widgets work internally (see AbstractHasData and its presenter).
>
> -- J.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/fRivwfFiUwIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to