I have been trying the new module functionality and I like what I see.
I encountered some little problems:
- The @LoadChildModuleError seems to be required when using chid
modules, which is fine, however at first didn't include it and I got a
nullpointer exception in stead of a nice exception that tells me to
include the annotation.
- By defining event methods on the parent event bus it is possible to
propragate events to the child module. But this always results in that
the start view of that event is shown. I believe it would be usefull
if it could be optional to show the start view of the child module.
- So it is possible to send events to a child module from its parent
module, but how do I send events from the child module to the parent?
This would be extremely usefull. For instance if I have a central
'alert' system in the root module then I would like to be able to
trigger it from the child module.
I have one point that isn't about the module system but about the
event system. The current version with annotation is almost type safe
which is a superb feature. However on thing that isn't type safe is
the method declaration of the event handler. In the event bus you
declare a method, for instance showView, and then you must be sure
that the event handler has a method 'onShowView'. It would be great if
this also could become type safe. I am not sure how however.
Keep up the great work.
Regards,
Maurice
Thanks for your feedback, I really appreciate it.
> - The @LoadChildModuleError seems to be required when using chid
> modules, which is fine, however at first didn't include it and I got a
> nullpointer exception in stead of a nice exception that tells me to
> include the annotation.
The first version of this feature didn't include any control. I will
add them in the next release.
> - By defining event methods on the parent event bus it is possible to
> propragate events to the child module. But this always results in that
> the start view of that event is shown. I believe it would be usefull
> if it could be optional to show the start view of the child module.
I guess it's something that could be implemented. But, why would you
want to load a child module if the user isn't gonna see? As a best
practice, shouldn't you load a module only when the user will interact
with it?
> - So it is possible to send events to a child module from its parent
> module, but how do I send events from the child module to the parent?
> This would be extremely usefull. For instance if I have a central
> 'alert' system in the root module then I would like to be able to
> trigger it from the child module.
One way you could do it, it's to attach parent's event bus to the
event when you load a child module:
public void goToChild(ParentEventBus eventBus);
But I guess it would be nice to have an easier system. One idea could
be to have the possibility to indicate if an event should be forwarded
to a parent:
@Event(...., forwardToParent=true)
public void displayMessage(String message)
In this case, parent should implement displayMessage. Now I'm not sure
if it can be implemented because when you build the child module, you
don't have access to parent module information. I have to take a
closer look at it.
> I have one point that isn't about the module system but about the
> event system. The current version with annotation is almost type safe
> which is a superb feature. However on thing that isn't type safe is
> the method declaration of the event handler. In the event bus you
> declare a method, for instance showView, and then you must be sure
> that the event handler has a method 'onShowView'. It would be great if
> this also could become type safe. I am not sure how however.
If you declare an handler that actually can't handle the event because
it doesn't define the right method (either because the method doesn't
exist or because the method doesn't have the right parameters), a
Java compilation error is raised and your GWT code won't be able to
compile. That's why I think handlers are type safe. Did you encounter
a type problem with handlers?
> Keep up the great work.
Thanks :)
-Pierre
Hi Maurice.
Thanks for your feedback, I really appreciate it.
The first version of this feature didn't include any control. I will
> - The @LoadChildModuleError seems to be required when using chid
> modules, which is fine, however at first didn't include it and I got a
> nullpointer exception in stead of a nice exception that tells me to
> include the annotation.
add them in the next release.
> - By defining event methods on the parent event bus it is possible toI guess it's something that could be implemented. But, why would you
> propragate events to the child module. But this always results in that
> the start view of that event is shown. I believe it would be usefull
> if it could be optional to show the start view of the child module.
want to load a child module if the user isn't gonna see? As a best
practice, shouldn't you load a module only when the user will interact
with it?
> - So it is possible to send events to a child module from its parentOne way you could do it, it's to attach parent's event bus to the
> module, but how do I send events from the child module to the parent?
> This would be extremely usefull. For instance if I have a central
> 'alert' system in the root module then I would like to be able to
> trigger it from the child module.
event when you load a child module:
public void goToChild(ParentEventBus eventBus);
But I guess it would be nice to have an easier system. One idea could
be to have the possibility to indicate if an event should be forwarded
to a parent:
@Event(...., forwardToParent=true)
public void displayMessage(String message)
In this case, parent should implement displayMessage. Now I'm not sure
if it can be implemented because when you build the child module, you
don't have access to parent module information. I have to take a
closer look at it.
> I have one point that isn't about the module system but about theIf you declare an handler that actually can't handle the event because
> event system. The current version with annotation is almost type safe
> which is a superb feature. However on thing that isn't type safe is
> the method declaration of the event handler. In the event bus you
> declare a method, for instance showView, and then you must be sure
> that the event handler has a method 'onShowView'. It would be great if
> this also could become type safe. I am not sure how however.
it doesn't define the right method (either because the method doesn't
exist or because the method doesn't have the right parameters), a
Java compilation error is raised and your GWT code won't be able to
compile. That's why I think handlers are type safe. Did you encounter
a type problem with handlers?
> Keep up the great work.Thanks :)
-Pierre
--
You received this message because you are subscribed to the Google Groups "Mvp4g" group.
To post to this group, send email to mv...@googlegroups.com.
To unsubscribe from this group, send email to mvp4g+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mvp4g?hl=en.
> Well I could think of cases where you want to send some information to a
> module that could use it as soon as it is displayed. But maybe that is
> simply a bad practice and the module should get the information as soon as
> it needs it.
So you actually think it's a better practice to send information right
away?
> I never thought of the possibility to simply send the eventBus with the>
> event call. However I am not sure if that is always that comfortable. For
> instance you are already within a module and you invoke an event to another
> part of the same module then you must make sure that the parent event bus is
> available for that part that is going to invoke the event. Being able to
> retrieve a parent module from some 'module global' point would be the most
> comfortable way.
What do you think of my idea to add a 'forwardToParent' attribute?
@Event(...., forwardToParent=true)
public void displayMessage(String message)
This could be implemented and still be type safe if I add the
following constraint: if you want to communicate with parentEventBus,
then you need to define the following method in your child module
interface:
public interface CompanyModule extends Mvp4gModule {
public void setParentEventBus(ParentEventBus
eventBus);
}
Thanks to this method, the Mvp4g compiler will be able to verify if
events that have to be forwarded to the parent are handled by the
parent event bus. Another advantage is that child presenter don't need
to know if an event is going to be forwarded to a parent or not.
Would this fit your need?
-Pierre
Hi Maurice,
So you actually think it's a better practice to send information right
> Well I could think of cases where you want to send some information to a
> module that could use it as soon as it is displayed. But maybe that is
> simply a bad practice and the module should get the information as soon as
> it needs it.
away?
> I never thought of the possibility to simply send the eventBus with the>What do you think of my idea to add a 'forwardToParent' attribute?
> event call. However I am not sure if that is always that comfortable. For
> instance you are already within a module and you invoke an event to another
> part of the same module then you must make sure that the parent event bus is
> available for that part that is going to invoke the event. Being able to
> retrieve a parent module from some 'module global' point would be the most
> comfortable way.
This could be implemented and still be type safe if I add the
@Event(...., forwardToParent=true)
public void displayMessage(String message)
following constraint: if you want to communicate with parentEventBus,
then you need to define the following method in your child module
interface:
public interface CompanyModule extends Mvp4gModule {
public void setParentEventBus(ParentEventBus
eventBus);
}
Thanks to this method, the Mvp4g compiler will be able to verify if
events that have to be forwarded to the parent are handled by the
parent event bus. Another advantage is that child presenter don't need
to know if an event is going to be forwarded to a parent or not.
Would this fit your need?
-Pierre
> > > Well I could think of cases where you want to send some information to a
> > > module that could use it as soon as it is displayed. But maybe that is
> > > simply a bad practice and the module should get the information as soon
> > as
> > > it needs it.
>
> > So you actually think it's a better practice to send information right
> > away?
>
> > I am not experienced enough in this types of applications to say what is
>
> better. I don't think it would be to complex to make it optional to show the
> view on a parent to child module event. Is there any good reason not to
> implement it?
It's actually not that easy to implement bc if you want to be able to
configure for each event, which module view should be load or not
because you need to find a way to easily represent it in xml and
annotations. Unfortunately, you can't have this:
@Event(modules={{Module1.class, true}, {Module2.class, false}, ..})
What can be easier is:
-either having the possibility to configure for an event that for all
the modules to load, module views should be loaded or not (ie either
you load module1 AND module2 views or you don't).
@Event(modules={Module1.class, Module2.class}, loadModulesView=false)
-or having the possibility to configure for a module if, for all
events, its view should be loaded (ie either you load view module for
event1 AND event2 or you don't). Then the child module will have to
manage when its view should be displayed by communicating with its
parent (with the new process, see next question)
@ChildModule(moduleClass= Module1.class, loadModuleView=false)
I'm not sure what solution would fit your need better (maybe 1?).
I think that as a best practice, you shouldn't load code or
instantiate objects that your user won't used that's why it may not be
a good idea to load a module if it's the user won't see it. After,
it's true that there are probably cases where you don't have the
choice.
My idea is that the presenter won't need to know if an event is
forwarded to the parent or not (the framework will manage it). The
less the presenter knows, the better (to prevent 'spaghetti effect').
So it won't need to call the setParentEventBus method. This method is
here just to allow framework to verify that events sent to parent
event bus are actually managed by parent event bus.
There is actually a better way to represent, you could have:
@Parent(ParentModule.class)
public interface CompanyModule extends Mvp4gModule {
}
In case the parent module is the main module, then you would have
@Parent(Mvp4gModule.class)
It shouldn't be too hard to implement so I will add it to Mvp4g 1.1.0
version.
-Pierre
-Pierre
After having thinking about it, I think the best way to do it it's to
implement the solution 2 I suggested before. Either you want the
framework to autoload view of a particular child module (which will be
the default behavior because I think it's the recommanded way to go)
or you don't want it and you manage it manualy (by settings a
communication from the child module to its parent).
You would then have sthg like that:
@ChildModules({
@ChildModule(moduleClass=..., autoload=false)
})
public class ParentEventBus .... {
@Event(module=...)
public void giveInfoToChild(InfoBean info)
@Event(module=...)
public void displayChild()
public void changeBody(Widget w);
}
public class ChildEventBus .... {
@Event(...)
public void giveInfoToChild(InfoBean info)
@Event(...)
public void displayChild()
@Event(forwardToParent=true)
public void changeBody(Widget w);
}
public class ChildPresenter .... {
public void giveInfoToChild(InfoBean info){
this.info = info;
}
@Event(...)
public void displayChild(){
eventBus.changeBody(w);
}
}
Do you see any problems with this solution?
> Regarding the @Parent annotation. It sounds like a good solution.
I actually realised when I started the implementation that I need a
setParentEventBus method in order the framework to be able to inject
the parent event bus to the child module. Since I have this method,
@Parent annotation is not needed anymore. You would have then
something like that:
public interface CompanyModule extends Mvp4gModule {
public void setParentEventBus(ParentEventBus
eventBus);
}
The purpose of this method is only for configuration (ie it is
analyzed and used only by the framework) so you will never have to
call it in your code.
-Pierre
-Pierre
I upload a new snapshot of Mvp4g that includes the communication from
child module to parent. Compared to the last discusion, I had to bring
one small change to give the possibility to manage history for sub
modules. Instead of defining a setter for the parent event bus, you
now need to define a setter for the parent module:
public interface ChildModule extends Mvp4gModule {
public void setParentModule(ParentModule parentModule);
}
If parent module is the root module of the application, then
ParentModule will be equal to Mvp4gModule. You can look at the
Mvp4gModules example to see it in action.
-Pierre
> > mvp4g+un...@googlegroups.com <mvp4g%2Bunsu...@googlegroups.com>.
> > For more options, visit this group at
> >http://groups.google.com/group/mvp4g?hl=en.- Hide quoted text -
>
> - Show quoted text -