Share mediatorMap between modules?

witchfinder's Avatar

witchfinder

26 Dec, 2012 09:53 AM

Hello fellow robotlegs users!

Here is my situation. I've got modular application where modules should dynamically add some view. These views are added into different containers that modules dont know. I use robotlegs modular utilities. So far I've come with following solution. There is a singleton-manager that registers containers and returns them when asked for. Views are defined within modules contexts and their mediators too. Modules fire events that trigger command for adding views (there are also events for removing views and updating them). This command asks the manager for appropriate container, creates view instance using classname (which it receives in event) and configurates it. Then it adds view to container.
The problem is in view mediation. MediatorMaps of parent application context and of modules are different objects. So command cannot create mediator for a view from module. There are few alternatives I thought of, all of them are quite awkward:
1) Somehow pass parent application's mediatorMap to modules so they could register mediators there
2) Map mediators somewhere else - in manager or even in commands
3) Define all desired views and their mediators within parent application's context - but I dont think they belong here.

I need some advice on how to solve this problem in a proper robotlegs-way.
Thanks in advance.

  1. Support Staff 1 Posted by Shaun Smith on 26 Dec, 2012 02:03 PM

    Shaun Smith's Avatar

    Hello,

    I'm struggling a little bit understanding what you're wanting to achieve. You mention this:

    So command cannot create mediator for a view from module

    But why does the command need to create a mediator at all? Surely the mediators that have been registered in the module context will just be auto-created when the correct views land on stage?

  2. 2 Posted by witchfinder on 27 Dec, 2012 08:13 AM

    witchfinder's Avatar

    Surely the mediators that have been registered in the module context will just be auto-created when the correct views land on stage?

    They doesnt seem to. Mediator is already mapped to view in module context at the moment when ADDED_TO_STAGE is fired by the view, but mediator's onRegister is not entered.

    Isn't it because module listens to ADDED_TO_STAGE on its contextView (which is spark.modules.Module component) and view is added into parent application contextView?

  3. 3 Posted by witchfinder on 27 Dec, 2012 11:16 AM

    witchfinder's Avatar

    Addition: when I'm trying to pass application as contextView for module like this

    [Inject]
    public function set parentInjector(value:IInjector):void {
         var contextView:DisplayObjectContainer = this.parentApplication as DisplayObjectContainer;
         context = new EffectsEditModuleContext(contextView, true, value, ApplicationDomain.currentDomain);
    }
    

    then module mediator (spark.modules.Module component) itself isn't getting Registered

  4. Support Staff 4 Posted by Shaun Smith on 27 Dec, 2012 03:50 PM

    Shaun Smith's Avatar

    module listens to ADDED_TO_STAGE on its contextView (which is spark.modules.Module component) and view is added into parent application contextView?

    Ah! So are you using the modules purely as class definition containers then? It sounds like the view components that you are mapping inside the modules are not actually being added into the context view for those modules?

    If that's the case then I wouldn't really bother with the Modular utility at all. Instead I would make the modules implement an interface. Something like:

    IViewMappingProvider
        function getViewMappings():<ViewMapping>
    
    ViewMapping
        public var viewClass:Class;
        public var mediatorClass:Class;
    

    After loading a module you'd then cast it to IViewMappingProvider and pull out the list of ViewMappings, loop through them, map the mediators into your root context and then construct and add the views to stage.

    Or, is that not quite what you're wanting to do?

  5. 5 Posted by witchfinder on 28 Dec, 2012 07:41 AM

    witchfinder's Avatar

    No, my modules do use own context views, but sometimes they need to add something outside.
    I solved my problem like it was suggested 2 threads under.
    In my ApplicationView:

    protected function preinitializeHandler(event:FlexEvent):void {
        var contextView:DisplayObjectContainer = SystemManager.getSWFRoot(this) as DisplayObjectContainer;
        this.context = new AppContext(contextView);
    }
    

    and in module:

    [Inject]
    public function set parentInjector(value:IInjector):void {
        context = new MyModuleContext(this.parentApplication as DisplayObjectContainer, true, value, ApplicationDomain.currentDomain);
    }
    

    Module and application now use same context view.

  6. Support Staff 6 Posted by Shaun Smith on 03 Jan, 2013 07:49 PM

    Shaun Smith's Avatar

    Hi, I'm closing this thread for now. If you have other questions please re-open or create a new thread. Thanks.

  7. Shaun Smith closed this discussion on 03 Jan, 2013 07:49 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