tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/50-mapping-mediators-across-multiple-windowsRobotlegs: Discussion 2018-10-18T16:35:09Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/11212072010-02-28T15:39:09Z2010-02-28T15:39:13Zmapping mediators across multiple windows<div><p>Hi,</p>
<p>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.</p>
<p>Is there a way to register another stage with the context, or is
there another way around this?</p>
<p>Cheers,</p>
<p>Owen</p></div>tag:robotlegs.tenderapp.com,2009-10-18:Comment/11212072010-02-28T17:09:38Z2010-02-28T17:09:38Zmapping mediators across multiple windows<div><p>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.</p>
<p>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.</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/11212072010-02-28T17:16:07Z2010-02-28T17:16:08Zmapping mediators across multiple windows<div><p>Hi,</p>
<p>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.</p>
<p>Owen</p></div>owentag:robotlegs.tenderapp.com,2009-10-18:Comment/11212072010-02-28T17:21:53Z2010-02-28T17:22:18Zmapping mediators across multiple windows<div><p>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 <em>meadiatorMap</em> available to it. Simply
create a <em>registerChildren</em> in <em>onRegister</em> to
facilitate this. You will also want to <em>unregisterChildren</em>
in the mediator's <em>onRemove</em>. Additionally you will probably
want to listen for the close event on the mediated window to
manually remove the window's mediator.</p>
<p>It is less "magical" than the convenient mechanism provided, but
certainly a lot easier than dealing with multiple contexts.</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/11212072010-02-28T17:31:43Z2010-02-28T17:31:43Zmapping mediators across multiple windows<div><p>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.</p>
<p>For example</p>
<p>set sharedZooModel(zooModel:IZooModel):void ;</p>
<p>this would pass the zooModel through to the context, which would
keep a reference to be used for the injection in startup.</p>
<p>In this workaround you'd need to set the zooModel before you ran
startup on the new window (passed through to the context).</p>
<p>Or - you can expose the context on the contextView (window root
view) and act directly on the window context.</p>
<p>As Joel says, another way is to manually mediate your views.</p>
<p>Either is going to be a little more code than if you weren't
doing a windowed Air app...</p>
<p>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.</p>
<p>Hope that helps,</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/11212072010-02-28T17:38:42Z2010-02-28T17:38:43Zmapping mediators across multiple windows<div><p>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!</p>
<p>Thanks for the advice,</p>
<p>Owen</p></div>owentag:robotlegs.tenderapp.com,2009-10-18:Comment/11212072010-02-28T17:41:02Z2010-02-28T17:41:02Zmapping mediators across multiple windows<div><p>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.</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/11212072010-02-28T17:49:03Z2010-02-28T17:49:03Zmapping mediators across multiple windows<div><p>Joel's right - unless your view has a <em>lot</em> of separately
mediated sub-views I'm pretty sure manual mediation is going to be
simpler.</p>
<p>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.</p></div>Stray