Share mediatorMap between modules?
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.
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
Support Staff 1 Posted by Shaun Smith on 26 Dec, 2012 02:03 PM
Hello,
I'm struggling a little bit understanding what you're wanting to achieve. You mention this:
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 Posted by witchfinder on 27 Dec, 2012 08:13 AM
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 Posted by witchfinder on 27 Dec, 2012 11:16 AM
Addition: when I'm trying to pass application as contextView for module like this
then module mediator (spark.modules.Module component) itself isn't getting Registered
Support Staff 4 Posted by Shaun Smith on 27 Dec, 2012 03:50 PM
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:
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 Posted by witchfinder on 28 Dec, 2012 07:41 AM
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:
and in module:
Module and application now use same context view.
Support Staff 6 Posted by Shaun Smith on 03 Jan, 2013 07:49 PM
Hi, I'm closing this thread for now. If you have other questions please re-open or create a new thread. Thanks.
Shaun Smith closed this discussion on 03 Jan, 2013 07:49 PM.