Modules inside Modules

Enrique's Avatar

Enrique

05 Nov, 2010 02:44 PM

Hi, I'm seeing the code of Modular Utilities, and it uses a global dispatcher ("moduleDispatcher") to communicate with other modules, but what happens if we need to communicate one module with it's parent module only not the entire application?

The moduleDispatcher is injected in ModuleContext inside "initializeModuleEventDispatcher():void" in this way:

    if(injector.hasMapping(IModuleEventDispatcher) )
        {
            moduleDispatcher = injector.getInstance(IModuleEventDispatcher);
        }
        else
        {
            moduleDispatcher = new ModuleEventDispatcher(this);
            injector.mapValue(IModuleEventDispatcher, moduleDispatcher); 
        }

So maybe we can redefine the mapping for IModuleEventDispatcher in our parent and share our moduleDispatcher between parent and child only.
But then we lose the global communication.
Is there a solution for this?

Thanks!
Enrique.

  1. Support Staff 1 Posted by Shaun Smith on 05 Nov, 2010 02:54 PM

    Shaun Smith's Avatar

    Hi Enrique,

    Nothing is truly "global" in Robotlegs. Feel free to bend the modular utils to suit your needs - it simply comes down to sharing plain old IEventDispatcher instances and using them how you see fit.

  2. 2 Posted by Stray on 05 Nov, 2010 03:00 PM

    Stray's Avatar

    Absolutely.

    There's no reason not to just create and share a ParentEventDispatcher and ParentCommandMap etc. You could just extend the existing Module ones and weave it in.

  3. 3 Posted by Enrique on 05 Nov, 2010 11:01 PM

    Enrique's Avatar

    OK, so there's no any "native" solution for the moment.
    I thought 3 possible solutions:
    Situation:
    Application has many "windows" modules.
    And each window has modules too.

    1) Create 2 more dispatcher in each Module, we will have 3 dispatchers then:
    eventDispatcher = self communication
    parentDispatcher = sends/receives messages to the parent module
    childDispatcher = sends/receives messages to the childs modules
    The childDispatcher of the parent Module is equal to the parentDispatcher of the current Module.
    And we must redispatch each Event if we want to reach a deeper level (it's like bubbling)
    We could have a 4th dispatcher: globalDispatcher for reaching every module in any level (=moduleDispatcher)

    CONS: we must change all classes of Modular Utilities and maybe it's a performance killer with so much dispatchers...

    2) Create a new class, based on a new interface IIsolator. This class has 3 dispatchers:
    eventDispatcher = self communication
    outsideDispatcher = sends/receive messages outside this module (parents in any level)
    innerDispatcher = sends/receive messages inside this module (childs in any level)
    So if we want for example our windows to receive events from other windows and the shell etc, but NOT from the modules inside other windows, we can make our Window implements IIsolator.
    In that situation:
    outsideDispatcher = shell.moduleDispatcher;
    insideDispatcher = new moduleDispatcher;
    childs.moduleDispatcher = insideDispatcher; //childs maybe need a new Injector.

    PROS: we don't need to change Modular Utilities, just extend it.
    CONS: it scares me.

    3) Each module must be a View for its parent and a Mediator for its childs.

    CONS: we can only dispatch outside our module from the MainView if we want to dispatch to our parents (because the parent mediator is listening that view), or from our Mediators if we want to dispatch to our childModules.
    And if this is not the actual option for modular applications I'm sure that's because it has a lot of problems.

    I don't like my options and I don't feel secure with any of them :(
    Maybe you can help me to find a solution. You are a lot smarter and more experienced than me.

    Thanks!

  4. Stray closed this discussion on 10 Feb, 2011 06:05 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac