mapping mediators across multiple windows
Hi,
I have an AIR application that uses multiple windows, which I want to be able to mediate with a single context. I figured that I needed to manually mediate the windows when they open from the main view, which works, but the sub components are also not mediated either. I figured that this was because each window has a separate stage and therefore was not generating the added to stage events for the main context.
Is there a way to register another stage with the context, or is there another way around this?
Cheers,
Owen
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
1 Posted by Stray on 28 Feb, 2010 05:09 PM
You could try using the modular approach - treat each window as if it's a separate swf - so each window has its own context with its own stage. Then use the inter-module event bus for communication between them.
If you need to share models / services between them then there are solutions for that too - but I'll let others fill you in on that if you need it as they know more.
2 Posted by owen on 28 Feb, 2010 05:16 PM
Hi,
Thanks for the reply. I had considered using separate contexts, but as you mention, I do need to share the model across the windows. Essentially the new windows are different views of the same data.
Owen
Support Staff 3 Posted by Joel Hooks on 28 Feb, 2010 05:21 PM
This is a problem with AIR in general. My suggestion would be to have the mediator of each window handle the manual mediation of its children via the meadiatorMap available to it. Simply create a registerChildren in onRegister to facilitate this. You will also want to unregisterChildren in the mediator's onRemove. Additionally you will probably want to listen for the close event on the mediated window to manually remove the window's mediator.
It is less "magical" than the convenient mechanism provided, but certainly a lot easier than dealing with multiple contexts.
4 Posted by Stray on 28 Feb, 2010 05:31 PM
Well, there are complex but very elegant solutions involving child injectors (which inherit injection rules from the parent), but one very simple workaround is to expose a method on the window views - which become the contextView for their individual contexts.
For example
set sharedZooModel(zooModel:IZooModel):void ;
this would pass the zooModel through to the context, which would keep a reference to be used for the injection in startup.
In this workaround you'd need to set the zooModel before you ran startup on the new window (passed through to the context).
Or - you can expose the context on the contextView (window root view) and act directly on the window context.
As Joel says, another way is to manually mediate your views.
Either is going to be a little more code than if you weren't doing a windowed Air app...
as I say - others might even be able to offer an even more elegant DI dependent solution - but either of these here would work. I'm guessing you know which is the least headache in your architecture.
Hope that helps,
Stray
5 Posted by owen on 28 Feb, 2010 05:38 PM
I think in this case, manually mediating might be the least complicated route, as I have a few parts of the model that the new context would require, but we shall see!
Thanks for the advice,
Owen
Support Staff 6 Posted by Joel Hooks on 28 Feb, 2010 05:41 PM
Manual mediation is very straight forward. You can look at the MyWindowMediator code and it immediately makes sense. It is a bit more verbose, but you should only have to do it once so that isn't too painful. I personally couldn't stomach the idea of using complex DI shenanigans, exposing the application layer on my view, or dealing with the relative complexity of multiple contexts for views that really aren't new contexts.
7 Posted by Stray on 28 Feb, 2010 05:49 PM
Joel's right - unless your view has a *lot* of separately mediated sub-views I'm pretty sure manual mediation is going to be simpler.
Separated contexts would really only be a good choice if your windows represented cleanly separated functional areas. If you're sharing models between them then it sounds like that's not the case.
Till Schneidereit closed this discussion on 02 Mar, 2010 12:46 PM.